Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. -- OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. DECLARE @NombreDepartamento nvarchar(50) = 'Engineering';
  4. DECLARE @NombreGrupo NVARCHAR(50) = 'Research and Development';
  5. DECLARE @Existe bit = 0;
  6.  
  7. IF EXISTS (SELECT Name FROM HumanResources.Department WHERE Name = @NombreDepartamento)
  8.     BEGIN
  9.         SET @Existe = 1;
  10.         GOTO OmitirInsertar;
  11.     END;
  12.  
  13. INSERT INTO HumanResources.Department
  14.     (Name, GroupName)
  15.     VALUES (@NombreDepartamento, @NombreGrupo);
  16.  
  17. OmitirInsertar: IF @Existe = 1
  18.     BEGIN
  19.         PRINT 'El departmento ' + @NombreDepartamento + ' ya existe en `HumanResources.Department`.';
  20.     END