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 2005 Forums
 Transact-SQL (2005)
 How to get a rownumber with 1 increments

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-02-26 : 16:50:16
I have the folliwing select query, is it possiblt to have an fake id column with rownumbers in it with the increments of 1.

Select id(fakeid), filenames, logtype, project from mytable


Thank you very much for the helpful info.

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-26 : 16:56:31
Row_Number can do this. See example.


Create table #temp(myname varchar(100))

insert into #temp(myname) values('Ted'),('John'),('Steve')

select ROW_NUMBER() over( order by myname),myname
from #temp

Mike
"oh, that monkey is going to pay"
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-26 : 16:59:38
select row_number() over(order by filenames asc) as id,filenames, logtype, project from mytable
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-02 : 04:47:49
Also refer
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -