15,741,818 members
See more:
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
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?

## Solution 1

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!
:)