Groups | Blog | Home
all groups > sql server data mining > september 2003 >

sql server data mining : Can I return the rowNumber in a select?


Erik Jensen
9/19/2003 9:11:31 AM
Is it possible to use a stored procedure that would select
data, but the first column in the resultset would be the
row index of the result set?

like

select (the row index),dataCol1, dataCol2 from tableName

results:

1, dataCol1, dataCol2
2, datacol1, dataCol2

etc..

Thanks
Anith Sen
9/22/2003 5:11:49 PM
There is no exposed "row index" in SQL Server. You can use correlated
subquery or a self join to achieve this in your resultset. Here is one
general method:

SELECT (SELECT COUNT(*)
FROM tbl t1
WHERE t1.keycol <= tbl.keycol) AS "row index"
col1, col2, ...
FROM tbl ;

-- where keycol is a unique column.

--
- Anith
( Please reply to newsgroups only )

AddThis Social Bookmark Button