Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
SELECT vEmpCode,SiteCode,ToDate,FromDate,Day(FromDate) As FDays ,Month(FromDate) As FromMonth,
Year(FromDate)As FromYear FROM Employee_Site_Tag
 Where [SiteCode]='SIT003'  AND [vEmpCode]='101407'
 AND  (  SELECT CASE    WHEN Year(FromDate) < 2013 THEN MONTH(FromDate)<= 12 WHEN Year(FromDate) = 2013 THEN MONTH(FromDate)<=1     END)
and ((  Month(ToDate) >= 1  and Year(ToDate) >= 2013 ) OR    Todate IS NULL  )










Error :Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '<'.
Posted
Comments
Aarti Meswania 12-Mar-13 1:25am    
what you want to do exactly?
Year(FromDate) < 2013 then you want to check MONTH(FromDate)<= 12 ?
Davidduraisamy 12-Mar-13 1:48am    
What you are trying to do...can u explain?

1 solution

this way...
SQL
SELECT vEmpCode,SiteCode,ToDate,FromDate,Day(FromDate) As FDays ,Month(FromDate) As FromMonth,
Year(FromDate)As FromYear 

FROM Employee_Site_Tag
 
Where [SiteCode]='SIT003'  AND [vEmpCode]='101407'
AND  
MONTH(FromDate)<= 
( 
CASE    WHEN Year(FromDate) < 2013 THEN 12 else case when Year(FromDate) = 2013 THEN 1 else 0 end END
)
and ((  Month(ToDate) >= 1  and Year(ToDate) >= 2013 ) OR    Todate IS NULL  )

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900