Question : SQL Query writing

hi
i am trying to write a basic query,

basically i want to pass a variable to @rate depending on what c.currency is


can anyone point out what i am doing wrong?

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
declare @rate as int

select h.customer,h.order_no,(d.val/@rate) as euro_sales,c.currency from scheme.opheadm h with(nolock)
	left join scheme.opdetm d on d.order_no = h.order_no
	left join scheme.slcustm c on c.customer = h.customer
case when (c.currency ='EUR') then @rate = '1.11'
else @rate ='0'
where h.status in (1,2,3,4,5,6,7,8) and h.status <> 'Q'

Answer : SQL Query writing

Hi,

If you only need the rate variable for that particular query then you should be able to use code snippet below.
1:
2:
3:
4:
5:
6:
7:
8:
9:
declare @rate as int

select h.customer,h.order_no,(d.val/case when (c.currency ='EUR') then 1.11 else 0 END) as euro_sales,c.currency 
		from scheme.opheadm h with(nolock)
        left join scheme.opdetm d 
				on d.order_no = h.order_no
        left join scheme.slcustm c 
				on c.customer = h.customer
		where h.status in (1,2,3,4,5,6,7,8) and h.status <> 'Q'
Random Solutions  
 
programming4us programming4us