tsql - column Calculation if column > 1in T-SQL -


hi trying calculate value of columns , depending if column value instance

if lens.qty > 1  (case lens.lns_progtype  --design points when 762 70 when 767 70 when 768 70 when 841 35 when 842 35 else 0 end + case ltrim(rtrim(lens.coattyp))   --arc points when 'hvll' 50 when 'hvllblue' 100 else 0 end + case lens.lns_idx   --material points when 53 35 when 56 35 when 58 35 when 61 35 else 0 end + case lens.lns_matclr  --color points when 00 0 when 46 35 when 47 35 when 48 35 else 0  end total_points)*lens.qty / 2  else  case lens.lns_progtype  --design points when 762 70 when 767 70 when 768 70 when 841 35 when 842 35 else 0 end + case ltrim(rtrim(lens.coattyp))   --arc points when 'hvll' 50 when 'hvllblue' 100 else 0 end + case lens.lns_idx   --material points when 53 35 when 56 35 when 58 35 when 61 35 else 0 end + case lens.lns_matclr  --color points when 00 0 when 46 35 when 47 35 when 48 35 else 0  end total_points) 

i keep getting syntax error , not sure going wrong not sure how , honest don't understand examples have viewed appreciated

i like:

(case   when lens.lns_progtype in (762,767,768) 70   when lens.lns_progtype in (841,842) 35   else 0 end + case ltrim(rtrim(lens.coattyp))   --arc points   when 'hvll'      50   when 'hvllblue'  100   else 0 end + case   when lens.lns_idx in (53,56,58,61) 35   else 0 end + case   when lens.lns_matclr in (46,47,48) 35   else 0 end) * case when lens.qty > 1 lens.qty / 2 else 1 end 

for entire expression. but, said, i'd introduce mapping tables rather having of these magic constants in case expressions.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -