Advertisement
Fhernd

InsercionDepartamento.sql

Jul 11th, 2015
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.63 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement