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.
| Author |
Topic |
|
gundavarapu
Starting Member
8 Posts |
Posted - 2003-09-02 : 01:21:53
|
| Hi All,How can we get the serial numbers for the result set of a query?For exampleSelect StudName. Marks from Student statement return 3 rows say,AAA 86BBB 49CCC 67i'd like to include a virtual column, which is not in the table, with the serial numbers for the rows like.,1 AAA 862 BBB 493 CCC 67...I hope you understood.ThanksRegards,Sidhu |
|
|
Frank Kalis
Constraint Violating Yak Guru
413 Posts |
Posted - 2003-09-02 : 02:02:43
|
Hi Sidhu,based on your sample data you could use something like CREATE TABLE ABC(a char(3),b int)GOINSERT INTO abc (a,b) VALUES('AAA',86)INSERT INTO abc (a,b) VALUES('BBB',49)INSERT INTO abc (a,b) VALUES('CCC',67)SELECT * FROM abcSELECT (SELECT COUNT(*) FROM abc t1 WHERE t1.a <= t2.a) AS MyID, t2.a, t2.bFROM abc t2ORDER BY 1On general this link should helphttp://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q186/1/33.asp&NoWebContent=1Cheers,Frank |
 |
|
|
SqlStar
Posting Yak Master
121 Posts |
|
|
gundavarapu
Starting Member
8 Posts |
Posted - 2003-09-03 : 08:48:26
|
Thanks to both of you.I figured the problem myself and came up with this solutionSELECT count(*) SerialNumber, a.strBookId FROM LibBooks a join LibBooks b on a.strBookId >= b.strBookId group by a.strBookId order by a.strBookId Regards,Sidhu |
 |
|
|
SqlStar
Posting Yak Master
121 Posts |
Posted - 2003-09-03 : 10:21:18
|
| Hi Sidhu,Are you seen that link? If u rdy to use #temp table, create an #temp table with an IDENTITY column, which starts from 1 and increment by 1. Your problem will be solved.Thanks":-) IT Knowledge is power :-)" |
 |
|
|
|
|
|
|
|