AnthonyWhitehouse
Programmer
Greetings - I have a sql trigger that sets the value on a field called SOH in the products table whenever the quantity for location 1 is updated.
This works - but sometimes it doesnt work. Investigating I think this is when the existing value of SOH is null.
I can not understand why this is - or how to resolve it - can someone please help - thanks.
My trigger is as follows
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trg_update_loc_quantity]
ON [dbo].[PLOCDETAILS] AFTER UPDATE
AS
IF UPDATE(quantityonhand)
BEGIN
update dbo.PRODUCTS
set dbo.Products.SOH = dbo.PLOCDETAILS.QuantityOnHand
from dbo.PRODUCTS
inner join dbo.PLOCDETAILS on dbo.PRODUCTS.UniqueID = dbo.PLOCDETAILS.ProductID Where PRODUCTS.uniqueid=(Select productid from inserted) and PLOCDETAILS.LocationNo = 1
END
This works - but sometimes it doesnt work. Investigating I think this is when the existing value of SOH is null.
I can not understand why this is - or how to resolve it - can someone please help - thanks.
My trigger is as follows
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trg_update_loc_quantity]
ON [dbo].[PLOCDETAILS] AFTER UPDATE
AS
IF UPDATE(quantityonhand)
BEGIN
update dbo.PRODUCTS
set dbo.Products.SOH = dbo.PLOCDETAILS.QuantityOnHand
from dbo.PRODUCTS
inner join dbo.PLOCDETAILS on dbo.PRODUCTS.UniqueID = dbo.PLOCDETAILS.ProductID Where PRODUCTS.uniqueid=(Select productid from inserted) and PLOCDETAILS.LocationNo = 1
END