TR_STOCKSALE_EXT_VALIDATE_IU
Definition
Copy
CREATE trigger TR_STOCKSALE_EXT_VALIDATE_IU on dbo.STOCKSALE_EXT for insert, update not for replication
as
begin
set nocount on
if exists(select 1 from FINANCIALTRANSACTION FT inner join dbo.STOCKSALE_EXT X on FT.ID = X.ID where (FT.POSTSTATUSCODE != 3 and FT.POSTDATE is null) and X.ID in (select ID from inserted))
raiserror('CK_STOCKSALE_POSTDATE_REQUIRED', 13, 1);
if exists(select 1 from FINANCIALTRANSACTION FT inner join dbo.STOCKSALE_EXT X on FT.ID = X.ID where FT.BASEAMOUNT < 0 and X.ID in (select ID from inserted))
raiserror('CK_STOCKSALE_SALEAMOUNTPOSITIVE', 13, 1);
if exists(select * from inserted where NUMBEROFUNITS<=0)
raiserror('CK_STOCKSALE_NUMBEROFUNITSPOSITIVE', 13, 1);
if exists(select * from inserted where NUMBEROFUNITS>dbo.UFN_STOCKDETAIL_REMAININGUNITS(STOCKDETAILID,ID))
raiserror('CK_STOCKSALE_NUMBEROFUNITSVALID2', 13, 1);
if exists(select * from inserted where FEE<0)
raiserror('CK_STOCKSALE_FEEPOSITIVE', 13, 1);
end