sábado, 20 de junio de 2015

WHILE in SQL Server

-- Example using AdventureWork Database

-- Sentencia WHILE

 BEGIN TRAN
     WHILE (SELECT MAX(p.ListPrice) FROM Production.Product AS p) < 5000
     BEGIN
         UPDATE Production.Product
         SET
             ListPrice = ListPrice * 2
            
         SELECT MAX(p.ListPrice) FROM Production.Product AS p
        
         IF (SELECT MAX(p.ListPrice) FROM Production.Product AS p) > 12000
         BEGIN
             SELECT 'Salimos'
             BREAK
         END
     END
 ROLLBACK TRAN

No hay comentarios:

Publicar un comentario