I have the following code:
declare c cursor for
select
id_user_V3
,device_type
,4
,notfication_mode
,t1.device_token
,registration_date
,rank
,1
from audiv2.dbo.mya_webservice_device_token t1
join migr.asoc_V2_glb_user t2 on t1.user_id = t2.id_user_V2
open c
fetch next from c into @id_user_v3,@type,@application_id,@notiffication,@device_tooken,@creation_date,@rang,@status
while @@FETCH_STATUS=0
begin
set @device_id = (ISNULL((SELECT MAX(id_device) FROM usr_device)+1,1))
SET IDENTITY_INSERT usr_device ON
insert into usr_device values
(
@device_id
,@id_user_v3
,@type
,@application_id
,@notiffication
,@device_tooken
,@creation_date
,@rang
,@status
)
SET IDENTITY_INSERT usr_device OFF
fetch next from c into @id_user_v3,@type,@application_id,@notiffication,@device_tooken,@creation_date,@rang,@status
end
close c
deallocate c
The error I get is :
An explicit value for the identity column in table ‘usr_device’ can only be specified when a column list is used and IDENTITY_INSERT is ON.
How can I solve this?
Thanks in advance
You need to mention all the column names explicity in the INSERT clause
insert into usr_device (col1, col2,…) values