473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Any Inbuilt function like Oracle's ROWNUM to retrive the order of records

Hi all

I would like to know the order in which the records are saved in a table. I am a beginner in SQL, in Oracle we have the ROWNUM to retrive the same. Any option for this in SQL Server???


Regards
Reshmi
Dec 6 '06 #1
3 5137
almaz
168 Expert 100+
Hi all

I would like to know the order in which the records are saved in a table. I am a beginner in SQL, in Oracle we have the ROWNUM to retrive the same. Any option for this in SQL Server???


Regards
Reshmi
There is no consistent way to get the order of records in DB (unless you are using a clustered index for the table and select rows with "order by" clustered index).
Nevertheless, in SQL Server 2005 there is a great ROW_NUMBER ranking function that allows you to enumerate resulting rows over some order. Simplest example:

Expand|Select|Wrap|Line Numbers
  1. create table #table(ID int identity(1,1), Name nvarchar(100))
  2. insert #table (Name) values ('Peter')
  3. insert #table (Name) values ('Andreas')
  4. insert #table (Name) values ('George')
  5. insert #table (Name) values ('Met')
  6. insert #table (Name) values ('Jack')
  7.  
  8. select AlphebeticNameOrder = row_number() over (order by Name), * 
  9. from #table
  10. order by ID
Dec 6 '06 #2
iburyak
1,017 Expert 512MB
I changed above code a bit to convert it to MSSQL

[PHP]create table #table(ID int identity(1,1), Name nvarchar(100))
go
insert #table (Name) values ('Peter')
insert #table (Name) values ('Andreas')
insert #table (Name) values ('George')
insert #table (Name) values ('Met')
insert #table (Name) values ('Jack')

select IDENTITY(int, 1,1) AS ID_Num, name into #numbered_rows from #table order by name

select * from #numbered_rows[/PHP]
Dec 7 '06 #3
almaz
168 Expert 100+
I changed above code a bit to convert it to MSSQL
My code is MSSQL :). But only for 2005 version of MS SQL Server.
Dec 8 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: chripa | last post by:
Hi all I use php with oracle database and i need function like mysql_data_seek i need to set the result pointer to the row number I need. can anyone help me? Thank you Chripa
5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
7
by: ¢Ğ¢ı¢ö | last post by:
I want to retrieve a range of record such as retrieving 11th to 20th records from 10000 records In SQL Server, i can use the "OFFSET" function. so i wanna ask does Oracle provide any function...
4
by: Terry Coccoli | last post by:
Has anyone created a user function to return the ordinal position based on numeric input? In other words, f(1) returns 'st', f(2) returns 'nd', f(3) returns 'rd', etc.
2
by: Rishi Kumar | last post by:
consider the following queries that deals with report pagination a ) select MYROWS.* from (select * from TABLE_NAME) MY_ROWS where rownum between 1 and 100 b) select * from TABLE_NAME where...
4
by: pierig.gueguen | last post by:
Hello, I would like to know if the equivalent Oracle rownum exist in SQLServer. Here is a sample SQL code to explain what I want to do : select jobs.name, jobs.job_id, jobs.description,...
2
by: krishhhna | last post by:
If we want to retrive 5,6,7 rows from a table,then we used rownum in a query in group by clause,but my doubt is rownum has individual values for each rows then how did you group rows based on...
4
by: Steve | last post by:
i know i know...just get over it. look at the date of the last post/response in an oracle ng. :) this is a mysql specific query. i want to do the same thing in oracle. i don't know how. the...
6
by: pradeep kaltari | last post by:
Hi All, I was just going through EMP table in oracle Scott schema. Say, I want to find out the first employee in alphabetical order who's name starts with 'A'. the following query gives me the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.