SQL Update 2 Columns from 1 Case -


i have code selects price based on logic. our choices target margin, average historical price, , market price (and these have been calculated). sometimes, want ignore logic , explicitly "for model, please use price, instead of might've picked". hold price used. sets price no problem:

update set [price] = case     when [logic override] = 1 [target margin price]     when [logic override] = 2 [average historical price]     when [logic override] = 3 [market price]     else [price]     end pricetable ([logic override] <> 4 , [logic override] not null) , [model_id] = coalesce(nullif(@modelid, ''), [model_id]) 

what want able set [pricing method]. must create whole new case statement when want set both price , pricing method to, say, $20 , 'target margin', respectively, if logic override 1? can't seem right syntax this.

you can create multiple sql logic in columns (as long trying update same table).

your desired results confusing , not sure need hope helps idea of updating multiple columns each different clauses. think trying ask.

 update  set [price] = (select case                     when [logic override] = 1 [target margin price]                     when [logic override] = 2 [average historical price]                     when [logic override] = 3 [market price]                     else [price]                    end                    pricetable                     ([logic override] <> 4 , [logic override] not null)                     , [model_id] = coalesce(nullif(@modelid, ''), [model_id]),        [pricing method] = (select '$20' [pricing method] pricetable [logic        override] = 1),        [price] =  (select '$20' [price] pricetable [logic override] = 1),       [target margin]  = (select '$20' [target margin] pricetable [logic override] = 1)  pricetable 

i don't recommend these types of updates because hard maintain (if there multiple logic, tables, etc. needs updated, cumbersome). recommend create update each column easier maintain, read , understood peers. each own.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -