| | |
can we get the position of record while retriving records in sql server 2003
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
hi
i am using sql server 2003. can we get the position of record / row index in sql server while retrieving records?
like in some case we fetch records as per our criteria. And if that time need to know the postion of particular record then? how to get that?
plz help.
i am using sql server 2003. can we get the position of record / row index in sql server while retrieving records?
like in some case we fetch records as per our criteria. And if that time need to know the postion of particular record then? how to get that?
plz help.
Accept Challenges and Enjoy Coding... :)
Re: can we get the position of record while retriving records in sql server 2003
1
#2 Mar 25th, 2008
Are you using a cursor?
If so, you could always create a counter variable and increment it each time through the loop. Is this done through an application, or the query window? If it's done in a application, you may need to create a temporary table, insert the counter, plus whatever info you want, then select all the records from it after you are done with the fetch loop. If you are running it in a query window, you can just print the output.
Here's an example using the temp table
It's probably not the best solution, but it would work.
If so, you could always create a counter variable and increment it each time through the loop. Is this done through an application, or the query window? If it's done in a application, you may need to create a temporary table, insert the counter, plus whatever info you want, then select all the records from it after you are done with the fetch loop. If you are running it in a query window, you can just print the output.
Here's an example using the temp table
SQL Syntax (Toggle Plain Text)
DECLARE @counter INT; @counter = 0; CREATE TABLE #temp (counter int, otherdata varchar(255)) --Use whatever columns you need. DECLARE tempCursor CURSOR FOR SELECT * FROM table OPEN tempCursor DECLARE @value AS INT --or whatever your datatype is FETCH NEXT FROM tempCursor INTO @value WHILE @@FETCH_STATUS = 0 BEGIN INSERT #temp (counter, otherdata) VALUES (@counter, 'otherdata') @counter = @counter+1 FETCH NEXT FROM tempCursor INTO @value END CLOSE tempCursor DEALLOCATE tempCursor SELECT * FROM #temp DROP TABLE #temp
It's probably not the best solution, but it would work.
Re: can we get the position of record while retriving records in sql server 2003
0
#3 Mar 25th, 2008
•
•
•
•
hi
i am using sql server 2003. can we get the position of record / row index in sql server while retrieving records?
like in some case we fetch records as per our criteria. And if that time need to know the postion of particular record then? how to get that?
plz help.
Note to self... pocket cup
Re: can we get the position of record while retriving records in sql server 2003
0
#4 Mar 26th, 2008
![]() |
Other Threads in the MS SQL Forum
- Previous Thread: looping in SQL Server2005
- Next Thread: Urgent - how to calculate rank in selected records in sql server 2000
| Thread Tools | Search this Thread |





