Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE #tempdemo (
- theId int IDENTITY(100,3),
- theField varchar(20)
- )
- DECLARE @NewId1 int
- DECLARE @NewId2 int
- INSERT INTO
- #tempdemo
- (theField)
- SELECT
- 'test1'
- --this would have a "from table" in a real situation
- WHERE
- 1 = 1
- SET @NewId1 = SCOPE_IDENTITY();
- INSERT INTO
- #tempdemo
- (theField)
- SELECT
- 'test2'
- --this would have a "from table" in a real situation
- WHERE
- 1 = 2 --obviously fails, in my real situation there are times the insert has nothing to insert
- SET @NewId2 = SCOPE_IDENTITY();
- select '@NewId1 = ', @NewId1, '@NewId2 = ', @NewId2
- drop table #tempdemo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement