Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 11, 2015 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/e9d143dcffb6cbe49bfb to your computer and use it in GitHub Desktop.
Save Fhernd/e9d143dcffb6cbe49bfb to your computer and use it in GitHub Desktop.
Uso de la sentencia GOTO.
-- 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