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.
| Author |
Topic |
|
Leggy
Starting Member
3 Posts |
Posted - 2009-11-06 : 10:08:56
|
| Hi, I need to simplify a stored procedure by combining 2 update statements before I submit it. Both statements are using the same tables, but are targeting different data within them.statements : 1.update ipd set carton_type = nullfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbrwhere iph.ord_type = 'SD' and iph.whse = @whse and iph.co = @co and iph.div = @divupdate ipd set carton_break_attr = pkt_seq_nbrfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbr and iph.ord_type = 'SD'join item_master im on ipd.cust_sku = im.vendor_item_nbr and im.std_pack_qty != '1' and (im.carton_type != 'UGL' or im.carton_type is null) and (im.spl_instr_code_3 != 'SP' or im.spl_instr_code_3 is NULL)where convert(int,ipd.orig_pkt_qty) % 12 = 0 2.update ipd set carton_break_attr = pkt_seq_nbrfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbr and iph.ord_type = 'SD'join item_master im on ipd.cust_sku = im.vendor_item_nbr and im.std_pack_qty = '1' and (im.carton_type != 'UGL' or im.carton_type is null) and (im.spl_instr_code_3 != 'SP' or im.spl_instr_code_3 is NULL)where convert(int,ipd.orig_pkt_qty) % 2 = 0 Or is it easier to run 2 statements?My SQL knowledge is not fantastic and will appreciate any replies.Cheers, Andy |
|
|
Leggy
Starting Member
3 Posts |
Posted - 2009-11-06 : 10:11:00
|
| Sorry, I pasted an extra statement at the top, the updates are:1. update ipd set carton_break_attr = pkt_seq_nbrfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbr and iph.ord_type = 'SD'join item_master im on ipd.cust_sku = im.vendor_item_nbr and im.std_pack_qty != '1' and (im.carton_type != 'UGL' or im.carton_type is null) and (im.spl_instr_code_3 != 'SP' or im.spl_instr_code_3 is NULL)where convert(int,ipd.orig_pkt_qty) % 12 = 0 and iph.whse = @whse and iph.co = @co and iph.div = @div2.update ipd set carton_break_attr = pkt_seq_nbrfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbr and iph.ord_type = 'SD'join item_master im on ipd.cust_sku = im.vendor_item_nbr and im.std_pack_qty = '1' and (im.carton_type != 'UGL' or im.carton_type is null) and (im.spl_instr_code_3 != 'SP' or im.spl_instr_code_3 is NULL)where convert(int,ipd.orig_pkt_qty) % 2 = 0 and iph.whse = @whse and iph.co = @co and iph.div = @div |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2009-11-06 : 10:28:20
|
quote: Originally posted by Leggy Sorry, I pasted an extra statement at the top, the updates are:1. update ipd set carton_break_attr = pkt_seq_nbrfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbr and iph.ord_type = 'SD'join item_master im on ipd.cust_sku = im.vendor_item_nbr and im.std_pack_qty != '1' and (im.carton_type != 'UGL' or im.carton_type is null) and (im.spl_instr_code_3 != 'SP' or im.spl_instr_code_3 is NULL)where convert(int,ipd.orig_pkt_qty) % 12 = 0 and iph.whse = @whse and iph.co = @co and iph.div = @div2.update ipd set carton_break_attr = pkt_seq_nbrfrom inpt_pkt_dtl ipd join inpt_pkt_hdr iph on ipd.pkt_ctrl_nbr = iph.pkt_ctrl_nbr and iph.ord_type = 'SD'join item_master im on ipd.cust_sku = im.vendor_item_nbr and im.std_pack_qty = '1' and (im.carton_type != 'UGL' or im.carton_type is null) and (im.spl_instr_code_3 != 'SP' or im.spl_instr_code_3 is NULL)where convert(int,ipd.orig_pkt_qty) % 2 = 0 and iph.whse = @whse and iph.co = @co and iph.div = @div
where(convert(int,ipd.orig_pkt_qty) % 12 = 0 OR convert (int,ipd.orig_pkt_qty) % 2 = 0) http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
Leggy
Starting Member
3 Posts |
Posted - 2009-11-06 : 10:35:27
|
| Many thanks guys. Much appreciated. |
 |
|
|
|
|
|
|
|