Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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



Thanks
AShish
 
Share this answer
 
Comments
itsureshuk 9-Aug-12 0:42am    
Thanks
AshishChaudha 9-Aug-12 1:17am    
always welcome
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.
 
Share this answer
 
Comments
itsureshuk 9-Aug-12 0:42am    
Thanks
Prasad_Kulkarni 9-Aug-12 0:48am    
Glad it helps.
You're welcome!
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,
 
Share this answer
 
Comments
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
Abdul Quader Mamun 9-Aug-12 1:20am    
was that helpful! don't be late to vote me.
itsureshuk 9-Aug-12 6:37am    
i voted

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