15,941,828 members
See more:
HI Frnds Good morning,
Table Name:Joining Details

Emp Name Joined Date
A 01-01-2012
B 02-05-2012
C 03-26-2012
D 04-23-2012
E 05-12-2012
F 06-12-2012
G 07-23-2012
H 08-18-2012
I 09-15-2012

From this table i need to get values of March 2012 to Jun 2012...
I need to compare by month and year

output as:

Emp Name Joined Date
C 03-26-2012
D 04-23-2012
E 05-12-2012
F 06-12-2012
Posted

## Solution 2

SQL
```SELECT created_date FROM oining_Details WHERE
year(JoinedDate) = 2012 and month(JoinedDate) between 3 and 6```

Thanks
AShish

itsureshuk 9-Aug-12 0:42am
Thanks
AshishChaudha 9-Aug-12 1:17am
always welcome

## Solution 3

Try this:
SQL
`SELECT * FROM [tableName] WHERE StartDate <= '03-26-2012' AND EndDate >= '06-12-2012'`

Alternatives:
2.
SQL
`SELECT * FROM table WHERE @date >= startdate AND @date <= enddate`

3.
SQL
`SELECT * FROM [table] WHERE date BETWEEN startdate AND enddate.`

itsureshuk 9-Aug-12 0:42am
Thanks
You're welcome!

## Solution 1

SQL
```SELECT * FROM Emp WHERE
-- Compare year
DATEPART(yyyy, JoinedDate) = 2012
-- compare month
AND (BETWEEN DATEPART(mm, JoinedDate) = 03 AND DATEPART(mm, JoinedDate) = 06)```

thanks,

itsureshuk 9-Aug-12 0:37am
if 2012 and 2013 year means have to give like this (BETWEEN DATEPART(yyyy, JoinedDate) = 2012 AND DATEPART(yyyy, JoinedDate) = 2013)
itsureshuk 9-Aug-12 0:43am
Thanks
was that helpful! don't be late to vote me.
itsureshuk 9-Aug-12 6:37am
i voted