
/****** Object:  Trigger [TRG_EST_PROD_CPL_INATIVACAO]    Script Date: 07/25/2013 18:55:42 ******/
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_PROD_CPL_INATIVACAO]'))
DROP TRIGGER [dbo].[TRG_EST_PROD_CPL_INATIVACAO]
GO
GO
GO
CREATE TRIGGER [dbo].[TRG_EST_PROD_CPL_INATIVACAO] ON [dbo].[EST_PROD_CPL] FOR UPDATE AS
begin
if update(STS_PROD)
	begin
		--Probe alterao na nota fiscal de sada quando j existe registro da transferncia
		IF EXISTS (SELECT 
						* 
				   FROM 
						INSERTED 
				   WHERE
						QT_EST <> 0
						AND STS_PROD=1
						)
		  begin
			RAISERROR ('Produto com estoque diferente de zero, nao podera ser inativado.',16, 1);
			ROLLBACK TRANSACTION;
			RETURN;
		  end 
	end
end