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 |
|
DEfusion
Starting Member
2 Posts |
Posted - 2005-03-08 : 13:02:39
|
I'm doing some insert selects - I need to insert an order counter into the target table that doesn't exist in the source table.I've tried the following :DECLARE @counter intSET @counter = 1SELECT TOP 12 colA, colB, @counter = @counter + 1, @counter AS orderCounter But I obviously get errors as you can't set data and get data within a SELECT at the same time. Anyone have any ideas as to how I could achieve this simply?Thanks in advance,-D |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-08 : 13:09:48
|
insert the data normally and then update the counter column:DECLARE @counter intSET @counter = 1UPDATE MyTableSET @counter = orderCounter = @counter + 1Go with the flow & have fun! Else fight the flow |
 |
|
|
DEfusion
Starting Member
2 Posts |
Posted - 2005-03-09 : 03:43:07
|
| That won't work as there is unique index on the counter column and another column - e.g. target table colB & counterCol have a joined unique index. I'm not sure of the proper way to say that. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-09 : 05:53:51
|
disable the index, update the table and reenable the index.Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|