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 |
|
dev45
Yak Posting Veteran
54 Posts |
Posted - 2004-10-14 : 09:34:26
|
| if i have a tableTableA(col1 varchar(10))with the following data:dataAdataB....dataJhow can i create/get an autoicrement field next to the data in my select statement ?the resultset should look likeid_____data--------------1______dataA2______dataB...10_____dataJ |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-10-14 : 09:43:09
|
drop it into a temp table?Create Table #tableA (col1 varchar(10))Insert Into #tableASelect 'dataA' Union All Select 'dataB' Union All Select 'dataC' Union All Select 'dataD'Union All Select 'dataE' Union All Select 'dataF' Union All Select 'dataG'Select * From #tableACreate Table #tableB (id int identity(1,1), col1 varchar(10))Insert Into #tableB (col1)Select col1 From #tableASelect * From #tableBDrop Table #tableADrop Table #tableB Corey |
 |
|
|
dev45
Yak Posting Veteran
54 Posts |
Posted - 2004-10-14 : 09:50:17
|
| anything with a single query ? (or am i asking for too much ?) ;) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-14 : 10:04:28
|
voila!Create table #tableA (col1 varchar(10))Insert Into #tableASelect 'dataA' Union All Select 'dataB' Union All Select 'dataC' Union All Select 'dataD'Union All Select 'dataE' Union All Select 'dataF' Union All Select 'dataG'Select rank=count(*), t1.* From #tableA t1, #tableA t2where t1.col1 >= t2.col1group by t1.col1Drop Table #tableA Go with the flow & have fun! Else fight the flow |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-10-14 : 10:05:08
|
depends on the specific data... if each record has a column that is unique and that the data can be sorted...Create table #tableA (col1 varchar(10))Insert Into #tableASelect 'dataA' Union All Select 'dataB' Union All Select 'dataC' Union All Select 'dataD'Union All Select 'dataE' Union All Select 'dataF' Union All Select 'dataG'Select * From #tableASelect id = (Select count(*) From #tableA Where col1<= A.col1), col1From #tableA ADrop Table #tableA Corey |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-10-14 : 10:05:56
|
[snipped]Corey |
 |
|
|
dev45
Yak Posting Veteran
54 Posts |
Posted - 2004-10-15 : 01:35:26
|
| thx a lot ;) |
 |
|
|
|
|
|