Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
SQL
create proc sp_backup
@fromdate date,
@todate date

as
begin
if not exists(select * from sys.objects where type_desc='USER_TABLE' and name='Process_Trn_backup' )
begin

insert into Process_Trn_backup select * from Process_Trn   where  Process_Date  between   @fromdate   and @todate

set identity_insert Process_Trn_backup on

delete from Process_Trn   where  Process_Date  between   @fromdate   and @todate

alter table Process_Trn_backup add  archived0n datetime ,archivedby varchar(150)

update Process_Trn_backup set archived0n =GETDATE () ,archivedby='Rajesh' where Process_Date  between   @fromdate   and @todate


end
else
begin

--update syscolumns set colstat = 0 --turn off bit 1 which indicates identity column
--where id = object_id('Process_Trn_backup') and name = 'column_name'
--go
set identity_insert Process_Trn_backup on



insert into Process_Trn_backup(Process_Trn_Pk,User_Fk,Process_Date,Login_Time,Logout_Time,Core_Time,Noncore_time,Zone_Name,archived0n,archivedby) select * ,'','' from Process_Trn   where  Process_Date  between   @fromdate   and @todate

 set identity_insert Process_Trn_backup off

delete from Process_Trn   where  Process_Date  between   @fromdate   and @todate
update Process_Trn_backup set archived0n =GETDATE () ,archivedby='Rajesh' where Process_Date  between   @fromdate   and @todate



end

end




if run this sp in sql i got error like can only be specified when a column list is used and IDENTITY_INSERT is ON.
Posted

go through the below 2 links

Here[^]

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57953[^]

Thanks
--RA
 
Share this answer
 
You'll have to mention that column in the insert statement and insert value for that as well.

Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900