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 |
sebasn
Starting Member
3 Posts |
Posted - 2010-06-22 : 15:49:33
|
Hi, I've been wondering if theres a way to "create" an "id field" within a table this insert statement:
insert into tableX (field1, field2, ..., field10) select (field1, field2, ..., field10) from table1 inner join table0 on id0 = id1 where id0 = @id0
As you may've guessed by now, that's inside an SP and I need to insert in, let's say field1, an "id field" but the data migth (and will be) duplicated (and the table already has an id of its own, so i can't change the id while executing), so after the insert tableX should look like this: field1 - field2 - ... - field10 1 - X2 - ... - X10 2 - X2 - ... - X10 . - .. - ... - ... . - .. - ... - ... N - X2 - ... - X10 1 <-- start the count once again...(btw the data it's not the same). I've tried with a subquery, such as (select count(*) from tableX where id = @id) but no luck while inserting like this. The only thing I can think of it's a cursor and multiple inserts, the thing is that I may've loads of info within the cursor, wich it's not a wise thing to do (according to what i've read). I've been trying to figure this out for quite some time now, and wouldn't like to use a cursor, but i'm running out of time...and ideas :p I dunno if the situation is clear enough, but any help provided is really apreciated. Thx in advance =) |
|
|
|
|