Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Case statement

$
0
0
Hi All,
I am facing issue in my case statemement situation is like this that my siteid ='A' then then dates should be specific target range and if siteid='B' then dates should be in specific range. My query is as follows

select wonum,pmnum,targstartdate,MONTH(targstartdate) as month,commodity,commoditygroup
from workorder where siteid='a'
and workorder.worktype='PM'
and workorder.pmnum is not null
CASE when workorder.siteid='a' then (workorder.targstartdate>'2013-01-01' and workorder.targstartdate<'2014-01-01')
when workorder.siteid='b'
THEN AND (workorder.targstartdate>'2013-01-01' and workorder.targstartdate< '2014-07-01')
ELSE AND (workorder.targstartdate>'2013-01-01')
END








so actually what i am trying to achieve here is when siteid='a' then

CASE when workorder.siteid='a' then (workorder.targstartdate>'2013-01-01' and workorder.targstartdate<'2014-01-01')


and when siteid='b' then

THEN AND (workorder.targstartdate>'2013-01-01' and workorder.targstartdate< '2014-07-01')


Please guide me in this regard. Cheers

Viewing all articles
Browse latest Browse all 13329

Trending Articles