Posted By

rengber on 02/18/09


Tagged

database tsql etl cursor


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

pauliehaha


Basic TSQL Cursor Syntax


 / Published in: SQL
 

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

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

  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

Report this snippet  

You need to login to post a comment.