Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 counting rows returned from select statement

Author  Topic 

ronaldmacdonald
Starting Member

2 Posts

Posted - 2004-09-15 : 04:36:49
Hi

Im running a select query and want to return the number of each row returned. This is a sequential number for each RETURNED record not the record number position that they occupy in the table. This appears to be difficult to implement? Anyone have any ideas - even using a temp table,variables?

Cheers

Ron

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-09-15 : 04:59:25
Are you looking for something like this?


SELECT IDENTITY(int, 1, 1) AS Counter,
field1, field2, field3
INTO #Temp
FROM MyTable
WHERE ...

SELECT * FROM #Temp

DROP #Temp



OS
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-15 : 05:02:26
is this what u need?

declare #myTempTable (id int identity, col1 int, other columns)
insert into #myTempTable (col1, other columns)
select col1, other columns
from myTable

if this is not what u need give us some sample data...

btw rows are not stored in a table in a perticular manner. they aren't orderen on anything unless u specify it in select.


Go with the flow & have fun! Else fight the flow
Go to Top of Page

ronaldmacdonald
Starting Member

2 Posts

Posted - 2004-09-15 : 10:33:02
spirit1 and mohdowais - i kinf of used a mixture of both your syntaxes for my particular scenario and it works a treat!

thanks guys/gals
Go to Top of Page
   

- Advertisement -