Monday, March 26, 2012

Insert with a Identity

Say you have a temp table with three columns (f1,f2,f3)
and you want to insert them into a permanent table that
has four columns (f1,f2,f3,f4) where f4 is an identity
column. Assuming you don't want to DTS, what is the
correct syntax to do this? I have tried things like
insert into permtable
select * from #temptable
values (f1, f2, f3)
but of course it fails. Any ideas?If you're not sensitive about what value gets placed in the identity column,
then all you need to do is qualify your destination columns in the insert.
That, and you don't want the "values..." line in your insert...select.
insert into permtable (colA, colB, colC)
select f1, f2, f3 from #temptable
"HTX" wrote:
> Say you have a temp table with three columns (f1,f2,f3)
> and you want to insert them into a permanent table that
> has four columns (f1,f2,f3,f4) where f4 is an identity
> column. Assuming you don't want to DTS, what is the
> correct syntax to do this? I have tried things like
> insert into permtable
> select * from #temptable
> values (f1, f2, f3)
> but of course it fails. Any ideas?
>|||"HTX" <anonymous@.discussions.microsoft.com> wrote in message
news:01e201c4a589$d2355670$a401280a@.phx.gbl...
> Say you have a temp table with three columns (f1,f2,f3)
> and you want to insert them into a permanent table that
> has four columns (f1,f2,f3,f4) where f4 is an identity
> column. Assuming you don't want to DTS, what is the
> correct syntax to do this? I have tried things like
> insert into permtable
> select * from #temptable
> values (f1, f2, f3)
> but of course it fails. Any ideas?
Have you tried:
insert into permtable (f1, f2, f3)
select * from #temptable
Steve

No comments:

Post a Comment