Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Case statement ...

$
0
0

Is there a way to run a select statement from a "then" in the sql server case/when statement?

 I read that select statment cannot be used inside case but is there a way achieve the below requirement. I cannot change the database design or  table structure.

select c.name,c.address
  case c.group
    when 6500 then (select amt from Table1 Where cust_id = c.cust_id)
    when 5450 then (select amt from Table2 Where cust_id = c.cust_id)
    when 2010 then (select amt  from Table3 Where cust_id = c.cust_id)
   else 0
  end as 'Amount'
From customers as c


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>