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)
 Problem with exec('set identity_insert tblnm on')

Author  Topic 

ChrisB
Starting Member

6 Posts

Posted - 2005-11-30 : 12:05:21
I've tried to use exec('set identity_insert <tblnm> on'), but it does not work. It says "The command(s) completed successfully." whenever I'm trying to set it 'off' or when I try to set it 'on' and another table does not have identity_insert on. But, it doesn't actually do anything. Using SET IDENTITY_INSERT <tblnm> ON / OFF always works.

Is execute not supposed to be used for SET commands? Any ideas?

Thanks,
Chris

ChrisB
Starting Member

6 Posts

Posted - 2005-11-30 : 12:53:34
It turns out that you have to do everything within a single EXEC, set identity_insert TblX on, insert TblX, set identity_insert TblX off. All one string, just spaces between commands.

Chris
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-01 : 05:30:36
When you use Dynamic SQL, you should use all in the same block

EXEC
(
'set identity_insert <tblnm> on'
--Do insertion
'set identity_insert <tblnm> off'
)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -