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 into table brings up identity problems

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-10-07 : 07:44:12
richard writes "i've bee trying to insert this data into an existing table that already has info in it. i just want to add these rows into the table this is the query


insert into tblinvoicing
select null, --this null 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

but i get this error message

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 assuming that the first null is the problem as this equates to the identifier in the table i want to insert into.
this unique identifier is a autonumber if that helps

i've tried fiddling with the identity function but i dont really know what i'm doing as i'm only a beginner

any help would be gratefully received"

nr
SQLTeam MVY

12543 Posts

Posted - 2002-10-07 : 07:48:52
name the columns and leave out the identity columns

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

==========================================
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 -