Forum Moderators: open
Basically it isn't working, but i don't know why 80( , plus i have no real idea how to debug or output things so i am struggling to find out why.
Any help would be much appreciated.
CREATE TRIGGER trgChgProd
ON Product
FOR UPDATE
AS
if UPDATE(stk_hld_uoi)
begin
declare @tx_type smallint, @tx_uoi float, @tx_prd int, @tx_opn_bal float, @tx_end_bal float, @tx_ord_check bit
select @tx_opn_bal = del.stk_hld_uoi FROM DELETED del
select @tx_end_bal = ins.stk_hld_uoi FROM INSERTED ins
select @tx_prd = ins.product_id FROM INSERTED ins
select @tx_uoi = ins.stk_hld_uoi FROM INSERTED ins
if(@tx_end_bal < @tx_opn_bal)
select @tx_type = '4'
else
select @tx_type = '3'
if(@tx_ord_check <> 1)
insert into Stock_Tx (product_id, order_id, raised_by,
raised_date, tx_type, tx_uoi,
tx_opn_bal, comment)
values (@tx_prd, 0, 0, getdate(), @tx_type,
@tx_uoi, @tx_opn_bal,'created by trgChgProd')
end
If I run into situations where the query isn't working, or isn't firing when supposed to, I go into debug mode.
It's not that difficult, but it is important.
The first friend you have (in ASP) is Response.Write(). In PhP I believe it is echo()
This will write values to the screen so you can test them.
First, comment any execute lines you might have that actually fire the query. Then echo or REsponse.Write the query to the screen, to see what you are sending to the database.
In your statements below you are comparing the values of two variables:
if(@tx_end_bal < @tx_opn_bal)
Do you know what the actual values are at that point? A good candidate for a response.write to actually see what they are.
Debugging is painstaking, but so important. In a nutshell, you need to see the values you are passing into variables to check your logic.