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 |
|
vendn5
Starting Member
1 Post |
Posted - 2006-12-19 : 13:02:06
|
| I'm populating a table (TMP_SQL) with data from several other tables in our database.I need to create through SQL commands a counter variable to fill TMP_SQL's KEY1 field. The data I'm pulling in from other tables does not have a field that is always 100% gaurenteed unique, so I need to create a counter for a key field.Pseudo code: insert into TMP_SQL(tmp_key1, tmp_general1, tmp_general2, tmp_number1, ....)select @counter, someColumn, someColumn2, (select column3 from other table returning 1 row),...from table1 where things = things.How can I implement @counter = @counter + 1? Is this possible? I tried:DECLARE @COUNTER INTSET @COUNTER = 0and then had @COUNTER = @COUNTER + 1 in my select statement; of course, I got the error about not being able to set variables in the same select as data-retrievalComputers never do what I tell them to... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-19 : 13:04:26
|
| Create a new column as IDENTITY(1, 1) column...Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|