Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 if/case statement within a where clause

Author  Topic 

jodders
Starting Member

41 Posts

Posted - 2012-01-26 : 09:42:53
Hi guys,

Having trouble putting an If statement together regarding showing a figure in a currency.

current my statement looks like this:

Where h.currency_code = 'gbp'and c.ar_status = 'O'and b.offc like 'u%'


I am trying to get to:

Where
if
OS.Tc_code = 'GBP' THEN h.currency_code = 'gbp'and c.ar_status = 'O'and b.offc like 'u%'
ELSE
OS.Tc_code = 'EUR' THEN h.currency_code = 'eur'and c.ar_status = 'O'and b.offc like 'u%'


I had a look at Case statement but keeping getting a syntax error, can you help?


where
CASE WHEN (OS.Tc_code = 'GBP' THEN(h.currency_code = 'gbp' and c.ar_status = 'O'and b.offc like 'u%')ELSE 0 END))
OR
CASE WHEN (OS.Tc_code = 'EUR' THEN (h.currency_code = 'eur' and c.ar_status = 'O'and b.offc like 'u%')ELSE 0 END))


J


sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-26 : 09:46:05
[code]WHERE
h.currency_code = CASE WHEN OS.Tc_code = 'GBP' THEN 'gbp' ELSE 'EUR' END
AND c.ar_status = 'O'and b.offc like 'u%'[/code]
Go to Top of Page

jodders
Starting Member

41 Posts

Posted - 2012-01-26 : 09:51:46
thanks sunitabeck for such a quick response. You make it look so easy

Go to Top of Page
   

- Advertisement -