Updating table data in SQL Server -


i have below sql statement. trying add 2 values based on conditions. if @isucmpresent 1 should 75*70 if @isevmpresent present should getting (75 * 70) + (75 * 8)

  set @isevmpresent = 1   set @isucmpresent = 1    update #maindata   set onetimeexpense = (case when @isucmpresent = 1 75 * 70 end) +                        (case when @isevmpresent = 1 75 * 8 end)   itemid = 'ecs' or itemid = 'ucm' 

the issue if @isucmpresent = 1 true sum fine if @isevmpresent = 1 true don't 75 * 8

you need add else clause case statements:

update #maindata     set        onetimeexpense  = (case when @isucmpresent = 1  75 * 70 else 0 end) +                       (case when @isevmpresent = 1  75 * 8  else 0 end) itemid in('ecs','ucm') 

without them return null , sql cannot add number , null.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -