Posted By


rengber on 02/18/09

Tagged


Statistics


Viewed 747 times
Favorited by 0 user(s)

Basic TSQL Cursor Syntax


/ Published in: SQL
Save to your folder(s)

Minimal syntax for cursor use. See URL for SQL 2005 options and improvements.


Copy this code and paste it in your HTML
  1. DECLARE @EntityName AS VARCHAR(100)
  2.  
  3. DECLARE DepNameCursor Cursor FAST_FORWARD
  4. FOR SELECT top 100 MailName FROM DepNameExt
  5.  
  6. OPEN DepNameCursor
  7. FETCH NEXT FROM DepNameCursor
  8. INTO @EntityName
  9.  
  10. WHILE @@Fetch_Status = 0
  11. BEGIN
  12.  
  13. INSERT INTO [UDC].[dbo].[Entity]
  14. ([Name])
  15. VALUES
  16. (@EntityName)
  17.  
  18. FETCH NEXT FROM DepNameCursor
  19. INTO @EntityName
  20. END
  21.  
  22. CLOSE DepNameCursor
  23. DEALLOCATE DepNameCursor

URL: http://msdn.microsoft.com/en-us/library/ms190028.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.