sql server - TSQL sum a column with the outcome of a case statement -


i looking @ making new column contain sum of column of raw data outcome of case statement.

example:

sku        standardcost         addon      combined ---         ------------         -----      -------- 001         0.578271             0.040194   0.618465 070         0.290721             0.039425   0.330146 223         0.446990             0          0.446990 

addon column computed field based on case statement. want create combined column within code... possible?

thanks!! rob =)

i updating code working with...

select   itemkey 'product number',   ltrim(rtrim([itemkey]))+'_'+ltrim(rtrim([plant]))+'_'+ltrim(rtrim([location])) 'key',   [item desc] 'product description',   plant 'location',   [location] 'warehouse',   standardcost 'variable cost',   --add on costing   case     when substring(itemkey,1,4) = '3121' , substring(itemkey,10,3) = '010' ((select  -- calculating tanker pricing *np product (pas & raw)                                                   standardcost                                                                                                   standard_cost                                                                                                   year=2099 --standard cost variable filter                                                   , itemkey = '3121-000-010-001'                                                    , [location] = 'dneo')-                                                   (select                                                   standardcost                                                                                                   standard_cost                                                                                                   year=2099                                                   , itemkey = '2121-000-010-001'                                                   , [location] = 'dneo'))      when substring(itemkey,1,4) = '3141' , substring(itemkey,10,3) = '010' ((select -- calculating tanker pricing yolk egg product (pas & raw)                                                   standardcost                                                                                                   standard_cost                                                                                                   year=2099 --standard cost variable                                                   , itemkey = '3141-000-010-001'                                                    , [location] = 'dneo')-                                                   (select                                                   standardcost                                                                                                   standard_cost                                                                                                   year=2099                                                   , itemkey = '2141-000-010-001'                                                   , [location] = 'dneo'))      when substring(itemkey,1,4) = '3181' , substring(itemkey,10,3) = '010' ((select -- calculating tanker pricing albumen (white) egg product (pas & raw)                                                   standardcost                                                                                                   standard_cost                                                                                                   year=2099 --standard cost variable                                                   , itemkey = '3181-000-010-001'                                                    , [location] = 'dneo')-                                                   (select                                                   standardcost                                                                                                   standard_cost                                                                                                   year=2099                                                   , itemkey = '2181-000-010-001'                                                   , [location] = 'dneo'))   else 0   end 'add on'   standard_cost    [year] = 2099  --2099 defines variable cost, 2017 or current year standard cost   , substring(itemkey,4,1) <> '6'  --oes products not show in list   , [location] in ('arem', 'awame', 'awche', 'awlem', 'fabb') -- selected locations display order   1 asc,   2 asc 

sure... don't need case statement.

select    *    ,combined = standardcost + addon    yourtable 

if needed case statement, like...

select    *    ,combined = case when somecolumn = 'something' standardcost + addon end    yourtable 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -