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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 inserting identity errors, help!

Author  Topic 

sagey
Starting Member

4 Posts

Posted - 2002-10-03 : 11:55:00
i'm trying to insert info into an existing table that already has info in it. i just want to add this info into it.
when i run this query...


insert into tblinvoicing
select null, --this is the problem i think
lcompanyid, brandedrenewals.ssubscribername, getdate(),
'Branded Renewals ' + brandedrenewals.renewalmonth,
brandedrenewals.smanucode, brandedrenewals.orderno, brandedrenewals.orderno,
null, brandedrenewals.servicetype, sshortdesc, seancode, null,
'brandedrenewal', null, brandedrenewals.jobcost, null,
null, null,null,null
from brandedrenewals
inner join BrandedRenewalSummary on brandedrenewals.smanucode
= BrandedRenewalSummary.smanucode
where brandedrenewals.status <> 0

i get this error

Server: Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'tblinvoicing' can only be specified when a column list is used and IDENTITY_INSERT is ON.

i'm asuming that the problem is the first null value because this equates to the unique identifier auto number in the destination table
i've fiddled around with the identity property but i'm not really sure if this is the thing to be doing as i'm a beginner.

any help would be most gratefully received

cheers

nr
SQLTeam MVY

12543 Posts

Posted - 2002-10-03 : 12:14:59
Name the columns

insert tbl (col1, col2, col3)
select ...

And miss out the identity column and it will be set automatically.
The insert will also work if you change the order of columns in the table now.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -