Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate A AutoNumber

Status
Not open for further replies.

lfcmd

Programmer
May 3, 2006
14
IE
HI All
When i run a view from sqlserver i would like for it to return a autonumber against each item selected

How would i go about this

Simple Example

Table setup

Name Age
M 18
C 19
D 18
F 21
G 18

Code:
Select * from table where age ='18'


Result i would like to see would be as follows

AutoNum Name Age
1 M 18
2 D 18
3 G 18


Any help grately appreciated
 
in SQL Server 2005 use ROW_NUMBER
in 2000 do something like this

create table #temp(AutoNum int identity, Name varchar(49) Age int)
insert #temp
Select name,age from table where age ='18'--where is the where clause??

select * from #temp
order by AutoNum

Denis The SQL Menace
SQL blog:
Personal Blog:
 
You cant create a Temp Table when using a view in sql server 2005 ?,

The reason i need this is, i am running one view against another, and need to be able to check a record against the next record in sequence
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top