I have a table_variable with some data now i need to INSERT it to the
table in database this table has identity column.
How can i get the all identities ?
Message posted via http://www.webservertalk.comINSERT into some table (Col1,col2,col3)
SELECT * from #TempTable
That would be the solution if your tablevariable doesnt contain the
estimated IDs (whereas the column list Col1col2 doenst contain the identity
column)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"ALK via webservertalk.com" <forum@.nospam.webservertalk.com> schrieb im
Newsbeitrag news:b21535e06dbb4ad697a79231b66b0487@.SQ
webservertalk.com...
>I have a table_variable with some data now i need to INSERT it to the
> table in database this table has identity column.
> How can i get the all identities ?
> --
> Message posted via http://www.webservertalk.com|||What do you want to do with the IDENTITY values when you've got them?
Assuming you just want to return a result, you can do something like
the following. Use an alternate key of the table:
INSERT INTO YourTable (key_col, x, y, z)
SELECT key_col, x, y, z
FROM @.table_var
SELECT T.id /* IDENTITY key */
FROM YourTable AS T
JOIN @.table_var AS V
ON T.key_col = V.key_col /* Alternate key */
You must always have an alternate key because IDENTITY should never be
the only key of a table.
David Portas
SQL Server MVP
--|||Thanks, exactly
Message posted via http://www.webservertalk.com
No comments:
Post a Comment