sql server - Function to evaluate which rows are not null and return an INT -


i trying calculate numeric value if rows checked in sql server. have done before on client side using .net code. trying within sql server script user based came me excel spread sheet looking input table.

days of week example

sun = 1 mon = 2 tue = 4 wed = 8 thr = 16 fri = 32 sat = 64 

input table

sysid sun mon tue wed thr fri sat ----- --- --- --- --- --- --- ---   1    0   0   1   0   1   0   0   2    1   1   1   1   1   1   1   3    0   0   0   1   0   0   1 

desired result

sysid dayofweek ----- ---------   1      20   2      127   3      68 

without writing 128 case statements or writing values table , doing sum function...i thinking function pass in values of 7 fields , add them , return value.

is there easier way this?

if understand trying do, might work:

select (case when sun=1 1  else 0 end)     +  (case when mon=1 2  else 0 end)     +  (case when tue=1 4  else 0 end)     +  (case when wed=1 8  else 0 end)     +  (case when thu=1 16 else 0 end)     +  (case when fri=1 32 else 0 end)     +  (case when sat=1 64 else 0 end)     dayofweek inputtable 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -