sql - SELECT using a case statement -


good afternoon

i new sql server strugling build select. looking advice dont know turn.

so have table need update if columns exist in other tables. other table have defualt value of 999, mean value. try , write sudo code.

select row master table between dates , cust in ( custtable cust matches or cust custtable = 999) , branch in ( branchtable branch matches or branch branchtable = 999) , product in ( producttable product matches or product producttable = 999) 

only if 3 equate being found should have row.

please let me know you require more information may not have made sense

thanks in advance. go easy on me sa learning

update

so have following

select @si_id = sic_idsupportedinitiative, @si_suppid = sic_idsupplier,  @sd = sic_startdate, @ed = sic_enddate, @si_amt = sic_claimamount sic_supportedinitiative sic_idsupportedinitiative = 1  select sc.id, sc.[actual posting date],sc.[customer account],   sc.[accounting branch],sc.[product code],sc.[salesq uantity],sc.sic_totalclaimamount salescurrent sc sc.[actual posting date] between @sd , @ed , exists  ( select 1 sic_customerdetails c     c.sic_idsupportedinitiative = @si_id       , c.sic_icc_customer = sc.[customer account] or c.sic_icc_customer = 999 ) , exists ( select 1 sic_branchdetails b     b.sic_idsupportedinitiative = @si_id       , b.sic_imo_branch = sc.[accounting branch] or b.sic_imo_branch = 999 ) , exists ( select 1 sic_productdetails p     p.sic_idsupportedinitiative = @si_id       , p.sic_supplierproductcode = sc.[product code] or            p.sic_supplierproductcode in (select sp.sic_supplierproductcode                                            sic_supplierproducts sp                                           sp.sic_idsupplier = @si_suppid                                             , sp.sic_supplierproductcode = sc.[product code]) )  going loop round need update sic_totalclaimamount   sic_totalclaimamount = sic_totalclaimamount + ( sc.[sales quantity] * @si_amt ) 

again if there easier way love hear.

thanks

i don't know rest of query looks like, can logic ware looking using exists:

from mastertable mt between dates ,       exists (select 1 custtable c c.cust = mt.cust or c.cust = 999) ,       exists (select 1 branchtable b b.branch = mt.branch or b.branch = 999) ,       exists (select 1 producttable p p.product = mt.product or p.product = 999)  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -