Created
July 11, 2015 12:41
-
-
Save Fhernd/e9d143dcffb6cbe49bfb to your computer and use it in GitHub Desktop.
Uso de la sentencia GOTO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- OrtizOL - xCSw - http://ortizol.blogspot.com | |
DECLARE @NombreDepartamento nvarchar(50) = 'Engineering'; | |
DECLARE @NombreGrupo NVARCHAR(50) = 'Research and Development'; | |
DECLARE @Existe bit = 0; | |
IF EXISTS (SELECT Name FROM HumanResources.Department WHERE Name = @NombreDepartamento) | |
BEGIN | |
SET @Existe = 1; | |
GOTO OmitirInsertar; | |
END; | |
INSERT INTO HumanResources.Department | |
(Name, GroupName) | |
VALUES (@NombreDepartamento, @NombreGrupo); | |
OmitirInsertar: IF @Existe = 1 | |
BEGIN | |
PRINT 'El departmento ' + @NombreDepartamento + ' ya existe en `HumanResources.Department`.'; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment