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

Case statement issue

$
0
0

I am using following query. My target is to achieve data between specific dates depending upon sites. But when i am using my query with this condition it is not giving me accurate results

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
and CASE  when workorder.siteid='a' then   (workorder.targstartdate>'2013-01-01' 
and  workorder.targstartdate<'2014-01-01') 
when workorder.siteid='b' 
THEN  (workorder.targstartdate>'2013-01-01' and  workorder.targstartdate< '2014-07-01') 
ELSE   (workorder.targstartdate>'2013-01-01') 
END


Viewing all articles
Browse latest Browse all 23857

Trending Articles