Oh, did i get into it now...First off, sorry for the long code, but I need some help. in our point-of-sale app we have a ticket line table PS_TKT_LIN, and a purchase order line table PO_ORD_LIN. The PO_ORD_LIN table has a trigger on it to update PS_TKT_LIN during receivings:CREATE trigger [dbo].[tr_UpdateTicketsorderstat2]on [dbo].[PO_ORD_LIN]for insert, update, deleteasset nocount onupdate tlset tl.ITEM_ORDER_STATUS = 'O',tl.item_order_no=rl.po_no,tl.LST_ITEM_STAT_DT = rh.ord_datfrom PO_ORD_LIN rl inner join PO_ORD_HDR rhon rh.PO_NO=rl.PO_NOinner join ps_tkt_lin tlon rl.COMMNT_1 = tl.tkt_noand rl.ITEM_NO=tl.ITEM_NOand rl.ps_tkt_lin_seq_no=tl.seq_noand rl.ps_tkt_lin_str_id=tl.str_idand rl.ps_tkt_lin_sta_id=tl.sta_idwhere not exists(select item_nofrom po_recvr_hist_lin plwhere pl.PO_NO=RL.PO_NOAND pl.ITEM_NO=RL.ITEM_NOAND pl.COMMNT_1=RL.COMMNT_1and pl.ps_tkt_lin_seq_no=tl.seq_noand pl.ps_tkt_lin_str_id=tl.str_idand pl.ps_tkt_lin_sta_id=tl.sta_id)update tlset tl.ITEM_ORDER_STATUS = 'R',tl.item_order_no=rl.po_no,tl.lst_item_stat_dt=pl.recvr_datfrom PO_ORD_LIN rl inner join ps_tkt_lin tlon rl.COMMNT_1 = tl.tkt_noand rl.ITEM_NO=tl.ITEM_NOand rl.ps_tkt_lin_seq_no=tl.seq_noand rl.ps_tkt_lin_str_id=tl.str_idand rl.ps_tkt_lin_sta_id=tl.sta_idinner join po_recvr_hist_lin plon pl.PO_NO=RL.PO_NOAND pl.ITEM_NO=RL.ITEM_NOAND pl.COMMNT_1=RL.COMMNT_1and pl.ps_tkt_lin_seq_no=tl.seq_noand pl.ps_tkt_lin_str_id=tl.str_idand pl.ps_tkt_lin_sta_id=tl.sta_idand (select sum(qty_recvd)from po_recvr_hist_lin plwhere pl.PO_NO=RL.PO_NOAND pl.ITEM_NO=RL.ITEM_NOAND pl.COMMNT_1=RL.COMMNT_1and pl.ps_tkt_lin_seq_no=tl.seq_noand pl.ps_tkt_lin_str_id=tl.str_idand pl.ps_tkt_lin_sta_id=tl.sta_idand pl.commnt_1 is not null)>=tl.qty_soldupdate tlset tl.ITEM_ORDER_STATUS = 'B',tl.item_order_no=rl.po_no,tl.lst_item_stat_dt=pl.recvr_datfrom PO_ORD_LIN rl inner join ps_tkt_lin tlon rl.COMMNT_1 = tl.tkt_noand rl.ITEM_NO=tl.ITEM_NOand rl.ps_tkt_lin_seq_no=tl.seq_noand rl.ps_tkt_lin_str_id=tl.str_idand rl.ps_tkt_lin_sta_id=tl.sta_idinner joinpo_recvr_hist_lin plon pl.PO_NO=RL.PO_NOAND pl.ITEM_NO=RL.ITEM_NOAND pl.COMMNT_1=RL.COMMNT_1and pl.ps_tkt_lin_seq_no=tl.seq_noand pl.ps_tkt_lin_str_id=tl.str_idand pl.ps_tkt_lin_sta_id=tl.sta_idand (select sum(qty_recvd)from po_recvr_hist_lin plwhere pl.PO_NO=RL.PO_NOAND pl.ITEM_NO=RL.ITEM_NOAND pl.COMMNT_1=RL.COMMNT_1and pl.ps_tkt_lin_seq_no=tl.seq_noand pl.ps_tkt_lin_str_id=tl.str_idand pl.ps_tkt_lin_sta_id=tl.sta_idand pl.commnt_1 is not null)<tl.qty_soldset nocount off
This trigger works fine, and takes no time to execute. Now, we have been tracking a problem where a ticket get partially released and then the remaining ps_tkt_lin items don't update from the above trigger. What we found is that when a ticket is partially released, the app reinserts the rows into PS_TKT_LIN with updated PS_TKT_LIN.SEQ_NO's. so now the trigger JOIN doesn't work. On the PS_TKT_LIN table is this trigger:CREATE trigger [dbo].[tr_UpdateItemShipDate]on [dbo].[PS_TKT_LIN]for insert, updateasset nocount onupdate tlset tl.TKT_SHIP_DAT = th.SHIP_DAT,tl.PROMPT_ALPHA_1 = ti.PROF_ALPHA_1,tl.PROMPT_ALPHA_2 = ti.PROF_ALPHA_2from inserted iinner join PS_TKT_LIN tlon i.STR_ID = tl.STR_IDand i.STA_ID = tl.STA_IDand i.TKT_NO = tl.TKT_NOand i.SEQ_NO = tl.SEQ_NOinner join IM_ITEM tion tl.ITEM_NO = ti.ITEM_NO join PS_TKT_HDR thon tl.STR_ID = th.STR_IDand tl.STA_ID = th.STA_IDand tl.TKT_NO = th.TKT_NO/* When TKT_SHIP_DAT is updated then update ITEM_SHIP_DATE in table PS_TKT_LIN under the following conditions:a) If ITEM_SHIP_DAT is NULL then set it to TKT_SHIP_DATb) If ITEM_SHIP_DAT is NOT NULL then only update if it matches old TKT_SHIP_DAT*/if update(TKT_SHIP_DAT)update tl settl.ITEM_SHIP_DAT=tl.TKT_SHIP_DATfrom PS_TKT_LIN tljoin deleted don tl.STR_ID=d.STR_IDand tl.STA_ID=d.STA_IDand tl.TKT_NO=d.TKT_NOwheretl.TKT_SHIP_DAT is not nulland (d.TKT_SHIP_DAT=tl.ITEM_SHIP_DAT or tl.item_ship_dat is null)set nocount off
Which at first blush we could add:UPDATE OLSET OL.PS_TKT_LIN_SEQ_NO=I.SEQ_NOFROM INSERTED IJOIN PO_ORD_LIN OLON OL.COMMNT_1=I.TKT_NOAND OL.ITEM_NO=I.ITEM_NOJOIN DELETED DON I.PO_NO=D.PO_NOAND I.ITEM_NO=D.ITEM_NOAND I.SEQ_NO=D.SEQ_NOAND D.PS_TKT_LIN_SEQ_NO=OL.PS_TKT_LIN_SEQ_NO
This works, but it is s-s-s-s-sl-l-l-l-o-o-o-o-w-w-w-w (upwards of 11 seconds
) to save a ticket. With all these triggers going back and forth, it is no wonder. Question is, how to handle this issue? We need this to wrok, and it needs to be more efficient. Should I take the trigger off of PO_ORD_LIN and turn it into a procedure? Or a function? Or take the trigger off PS_TKT_LIN and do this? Or both? How to go about it
AndyThere's never enough time to type code right, but always enough time for a hotfix...