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 |
|
real_pearl
Posting Yak Master
106 Posts |
Posted - 2004-08-16 : 07:26:34
|
| is it possible to add a counter column in a select statement likeselect pub_id, pub_name from pubsand if there are 5 rows then we shall get output ascounter pub_id pub_name1 P1 A2 P2 B3 P3 C4 P99 D5 P105 Eand counter is a self created column, not table's column |
|
|
cDc
Starting Member
30 Posts |
Posted - 2004-08-16 : 07:36:13
|
| Hi therethe only way I know of to achieve this is to create a temporary table (or better a table variable) with an identity column - as such:DECLARE @tempt table (counter int IDENTITY, pub_id int,pub_name varchar(50))INSERT INTO @tempt(pub_id,pub_name) SELECT pub_id,pub_name FROM pubsSELECT counter,pub_id,pub_name FROM @tempthope this helps |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-16 : 07:44:15
|
| SELECT IDENTITY(int,1,1) AS colID, col1, col2into #tempFROM MyTable select * from #tempGo with the flow & have fun! Else fight the flow :) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
real_pearl
Posting Yak Master
106 Posts |
Posted - 2004-08-16 : 08:10:57
|
Thanks spirit |
 |
|
|
|
|
|
|
|