Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. CREATE TABLE #tempdemo (
  2. theId int IDENTITY(100,3),
  3. theField varchar(20)
  4. )
  5.  
  6. DECLARE @NewId1 int
  7. DECLARE @NewId2 int
  8.  
  9. INSERT INTO
  10. #tempdemo
  11. (theField)
  12. SELECT
  13. 'test1'
  14. --this would have a "from table" in a real situation
  15. WHERE
  16. 1 = 1
  17.  
  18. SET @NewId1 = SCOPE_IDENTITY();
  19.  
  20. INSERT INTO
  21. #tempdemo
  22. (theField)
  23. SELECT
  24. 'test2'
  25. --this would have a "from table" in a real situation
  26. WHERE
  27. 1 = 2 --obviously fails, in my real situation there are times the insert has nothing to insert
  28.  
  29. SET @NewId2 = SCOPE_IDENTITY();
  30.  
  31.  
  32. select '@NewId1 = ', @NewId1, '@NewId2 = ', @NewId2
  33.  
  34.  
  35. drop table #tempdemo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement