Ver Mensaje Individual
  #4 (permalink)  
Antiguo 24/06/2015, 09:51
Avatar de iislas
iislas
Colaborador
 
Fecha de Ingreso: julio-2007
Ubicación: Mexico, D.F.
Mensajes: 6.482
Antigüedad: 17 años, 8 meses
Puntos: 180
Respuesta: Reemplazar Cursor SQL

Si vas a SAN GOOGLE y buscas, encontraras ejemplos, como este:

1. Create a temp table with an identity column that auto-increments, starting at 1 and going up by 1.
Código SQL:
Ver original
  1. CREATE TABLE #Temp1 (
  2.      ID INT IDENTITY(1,1),
  3.      ItemName VARCHAR(50),
  4.      ItemDescription VARCHAR(50)
  5.    ) .

2. Get the data inserted for review (you do not need to insert the ID field, it is being inserted with numbers increasing by 1 and starting at 1).
Código SQL:
Ver original
  1. INSERT INTO #Temp1(
  2.      ItemName,
  3.      ItemDescription
  4.    )
  5.    SELECT ItemName,
  6.      ItemDescription
  7.    FROM InventoryTable .

3. Create the loop and cycle through the data.
Código SQL:
Ver original
  1. DECLARE @Counter INT
  2.    SET @Counter = 1
  3.  
  4.    DECLARE @ItemReview VARCHAR(50)
  5.  
  6.    WHILE @Counter <= (SELECT COUNT(*) FROM InventoryTable)
  7.    BEGIN
  8.      SELECT @ItemReview = t.ItemName
  9.      FROM #Temp1 t
  10.      WHERE t.ID = @Counter
  11.  
  12.      IF @ItemReview = 'Tomatoes'
  13.      BEGIN
  14.          Do something here&#8230;.
  15.      END
  16.  
  17.      SET @Counter = @Counter + 1
  18.  
  19.    END
__________________
MCTS Isaias Islas