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)
 Adding row count to 'select' statement

Author  Topic 

loiter99
Starting Member

38 Posts

Posted - 2005-04-27 : 12:23:23
Hello,
Is there a function that will allow me to add a row count to my queries? I have been dropping in a subquery to get the total count of rows, but I would like something cleaner.

thanks

J

Kristen
Test

22859 Posts

Posted - 2005-04-27 : 13:34:22
SELECT * FROM MyTable WHERE MyColumn = '1'
SELECT @@ROWCOUNT AS [MyRowCount]

??

Kristen
Go to Top of Page

loiter99
Starting Member

38 Posts

Posted - 2005-04-29 : 07:44:51
Nope, that isn't it, but thanks for the reply.

In QA, the row number is displayed next to each item. I want to get that row number in the actual query. So for example:

Select *, [row number] from myTable99

Is there a function or a way to put a looping variable that will increment in for [row number] ?

thanks again
J
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-04-29 : 07:48:44
you can use a temp table for this. no such function in SQL server.

use northwind
select identity(int, 1, 1) as id, customerid
into #temp
from orders

select * from #temp

drop table #temp



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

loiter99
Starting Member

38 Posts

Posted - 2005-04-29 : 12:19:02
AHHH, that is IT !!!!

thx a million

J
Go to Top of Page
   

- Advertisement -