SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Recordset Numbering in SQL Server queries
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mantis
Starting Member

Italy
1 Posts

Posted - 11/29/2001 :  11:05:44  Show Profile  Visit mantis's Homepage  Reply with Quote
Hi,

I've to number the records in a SQL query made with SQL Server 2000. I need a field containing the number of that specific row starting from 1 and ending with the number of records retrieved.

Example

1, Field1, Field2, Field2....., FieldN
2, Field1, Field2, Field2....., FieldN
3, Field1, Field2, Field2....., FieldN
.....
N, Field1, Field2, Field2....., FieldN

Where the first field will contain the row number.
Can someone help me?

Thanks


Even the smallest person may change the course of the future!

sica
Posting Yak Master

Sweden
143 Posts

Posted - 11/29/2001 :  11:15:08  Show Profile  Send sica an ICQ Message  Reply with Quote
In SQL SERVER 7.0 I would put the result of the query in a temp table with an incremental column and do a new select from the temp table.

In SQL SERVER 2000 ,maybe a function would help you...

Sica

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

Australia
4970 Posts

Posted - 11/29/2001 :  17:23:05  Show Profile  Visit Merkin's Homepage  Reply with Quote
I don't think a funtion would help too much, but in SQL 2000 using a table variable instead of a temp table is a little faster.

Or, this might help get the specific rows
http://www.sqlteam.com/item.asp?ItemID=566



Damian
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000