Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 conditional insert

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-07-21 : 13:57:05

Want to set up a trigger that will only insert records into another table if the qty_bkord is not zero.

Tables:
oelinhst_sql
OrderRebateHistory

When records are inserted into the oelinhst if the qty_bkord is not zero then insert records into the OrderRebateHistory.

This is what I have so far but I get a message
"inserted.qty_bkord could not be bound."


begin
if inserted.qty_bkord <> 0
insert into OrderRebateHistory(ord_type,
ord_no,
line_seq_no,
status,
item_no,
price,
rebate_pct,
qty_ordered,
qty_to_ship,
cus_no,
AccountTypeCode,
cd_tp,
inv_no,
freefield3,
A4ID)
select
inserted.ord_type,
inserted.ord_no,
inserted.line_seq_no,
orderrebate.status,
orderrebate.item_no,
orderrebate.price,
orderrebate.rebate_pct,
inserted.qty_ordered,
inserted.qty_to_ship,
inserted.cus_no,
orderrebate.AccountTypeCode,
orderrebate.cd_tp,
orderrebate.inv_no,
orderrebate.freefield3,
orderrebate.A4ID
FROM inserted INNER JOIN
oelinhst_sql ON inserted.ord_type = oelinhst_sql.user_def_fld_5 and
inserted.item_no = oelinhst_sql.item_no AND inserted.ord_no = oelinhst_sql.ord_no AND
inserted.inv_no = oelinhst_sql.inv_no join orderrebate on inserted.ord_type = orderrebate.ord_type and
inserted.item_no = orderrebate.item_no and inserted.ord_no = orderrebate.ord_no
end

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-21 : 14:00:28
you dont reuire if. just do like this:-
insert into OrderRebateHistory(ord_type,
ord_no,
line_seq_no,
status,
item_no,
price,
rebate_pct,
qty_ordered,
qty_to_ship,
cus_no,
AccountTypeCode,
cd_tp,
inv_no,
freefield3,
A4ID)
select
inserted.ord_type,
inserted.ord_no,
inserted.line_seq_no,
orderrebate.status,
orderrebate.item_no,
orderrebate.price,
orderrebate.rebate_pct,
inserted.qty_ordered,
inserted.qty_to_ship,
inserted.cus_no,
orderrebate.AccountTypeCode,
orderrebate.cd_tp,
orderrebate.inv_no,
orderrebate.freefield3,
orderrebate.A4ID
FROM inserted INNER JOIN
oelinhst_sql ON inserted.ord_type = oelinhst_sql.user_def_fld_5 and
inserted.item_no = oelinhst_sql.item_no AND inserted.ord_no = oelinhst_sql.ord_no AND
inserted.inv_no = oelinhst_sql.inv_no join orderrebate on inserted.ord_type = orderrebate.ord_type and
inserted.item_no = orderrebate.item_no and inserted.ord_no = orderrebate.ord_no
WHERE inserted.qty_bkord <>0
Go to Top of Page
   

- Advertisement -