Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. -- OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. -- Deshabilita mostrar contador de filas en los resultados:
  4. SET NOCOUNT ON;
  5.  
  6. -- 0. Declaración de variables auxiliares:
  7. DECLARE @IDTienda as INT;
  8. DECLARE @NombreTienda as NVARCHAR(50);
  9.  
  10. -- 1. Declaración de variable CURSOR:
  11. DECLARE @cursor_tienda as CURSOR;
  12.  
  13. SET @cursor_tienda = CURSOR FOR
  14. SELECT BusinessEntityID, Name
  15.  FROM Sales.Store;
  16.  
  17. -- 2. Apertura del cursor
  18. OPEN @cursor_tienda;
  19.  
  20. -- 3. Recuperación de registros uno a la vez:
  21. FETCH NEXT FROM @cursor_tienda INTO @IDTienda, @NombreTienda;
  22.  
  23. -- 4. Ciclo para iterar cada registro:
  24. WHILE @@FETCH_STATUS = 0
  25. BEGIN
  26.  PRINT 'ID Tienda: ' + cast(@IDTienda as VARCHAR (50)) + ' - Nombre Tienda: ' + @NombreTienda;
  27.  FETCH NEXT FROM @cursor_tienda INTO @IDTienda, @NombreTienda;
  28. END
  29.  
  30. -- 5. Cierre del cursor:
  31. CLOSE @cursor_tienda;
  32.  
  33. -- 6. Liberación de recursos del cursor:
  34. DEALLOCATE @cursor_tienda;