Codigo para trigger, funciones y procesos

Solo disponible en BuenasTareas
  • Páginas : 2 (350 palabras )
  • Descarga(s) : 0
  • Publicado : 14 de noviembre de 2011
Leer documento completo
Vista previa del texto
//***
CODIGO DE UN TRIGGER EN SQL SERVER
***//

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

--=============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER TRIGGER [ART_PRECIO] ON [dbo].[ARTICULO]
FOR INSERT,UPDATE ASDECLARE @IdArt AS INT;
DECLARE @Costo AS MONEY;


Select @IdArt = i.idarticulo From inserted i;
Select @Costo = i.Costo From inserted i;

BEGIN
SET NOCOUNT ON;UPDATE ARTICULO SET Precio=@Costo*1.5,Costo_prom=@Costo
WHERE idarticulo=@IdArt

END

//***
CODIGO DE UN TRIGGER EN SQLSERVER
***//

************************************************************************************************************************

//***CODIGO DE UN STORED PROCEDURE SQL SERVER
***//

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:
-- Createdate:
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[EXISTENCIA] (@idArt as Int)
-- Add the parameters for the stored procedure here
AS
BEGIN-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECTsum(
case when tipomov='E' then cantidad
else
cantidad*-1
end
) existencia
FROM MOVIMIENTOwhere idarticulo=@idArt;
END
GO

//***
CODIGO DE UN STORED PROCEDURE SQL SERVER
Exec spNAME param 1,param 2…, Param n

Exec...
tracking img