Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
alter PROCEDURE SP_TRUNCATE_AND_RESTORE
	  @CustDetails dbo.TempCustDetails readonly --User Define Table
AS
BEGIN
truncate table dbo.TBL_CUSTDETAILS 
SET IDENTITY_INSERT dbo.TBL_CUSTDETAILS ON 

insert into dbo.TBL_CUSTDETAILS
	select * from @CustDetails 
	
	
	SET IDENTITY_INSERT dbo.TBL_CUSTDETAILS OFF 
	
END
GO


Error

SQL
Msg 8101, Level 16, State 1, Procedure SP_TRUNCATE_AND_RESTORE, Line 13
An explicit value for the identity column in table 'dbo.TBL_CUSTDETAILS' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Posted

try this way...:)


SQL
SET IDENTITY_INSERT [MyDB].[dbo].[Equipment] ON
INSERT INTO [MyDB].[dbo].[Equipment] (COL1, COL2) SELECT (COL1, COL2) FROM [MyDBQA].[dbo].[Equipment]
SET IDENTITY_INSERT [MyDB].[dbo].[Equipment] OFF
 
Share this answer
 
Comments
Member-515487 9-Jul-13 11:33am    
not work
Try this

alter PROCEDURE SP_TRUNCATE_AND_RESTORE
	  @CustDetails dbo.TempCustDetails readonly --User Define Table
AS
BEGIN
truncate table dbo.TBL_CUSTDETAILS 
SET IDENTITY_INSERT dbo.TBL_CUSTDETAILS ON 
 
insert into dbo.TBL_CUSTDETAILS (identityCol1, col2, col3)
	select identityCol1, col2, col3 from @CustDetails 
	
	
	SET IDENTITY_INSERT dbo.TBL_CUSTDETAILS OFF 
	
END
GO
 
Share this answer
 
Comments
Member-515487 9-Jul-13 11:34am    
tried not working
_Asif_ 10-Jul-13 0:20am    
how you tried? give us details about TBL_CUSTDETAILS and @CUSTDetails

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