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
 General SQL Server Forums
 New to SQL Server Programming
 Identity Number

Author  Topic 

rameshsri
Starting Member

2 Posts

Posted - 2011-06-22 : 07:41:02
Hi,
I am adding one name table

Id Name Age Address
1 gokul 25 bigst
2 srikanth 27 bigst
3 imran 25 bigst
4 karthick 30 bigst
5 sathish 25 bigst

now i am creating one selected sp which is who are all in age 25 so the result is

Id Name Age Address
1 gokul 25 bigst
3 imran 25 bigst
5 sathish 25 bigst

It executes fine but i want there is 3 names out of 5 names the result is should be printed like this


Id Name Age Address SNO
1 gokul 25 bigst 1
3 imran 25 bigst 2
5 sathish 25 bigst 3

So i want one more column so display the serial no

i dont know how it done



Ramesh Srinivasan

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-06-22 : 07:49:17
If you are on SQL 2005 or higher, you can do this using the row_number() function. You would add a column to your query, something like this:

row_number() over(order by Id) as SNO
Go to Top of Page

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-06-22 : 07:49:25
which version you are using ?

In Love... With Me!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-29 : 04:24:38
Also see what you can do with row_number() function
http://beyondrelational.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 -