Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to retrieve all male records born in march from my sql database. the date
data is saved like 2000-03-11 00:00:00:00
i tried using this query but it returned no result. please help me out

SQL
SELECT FormattedMembershipid, Surname, Othername, REPLACE(CONVERT(NVARCHAR, Dateofbirth, 106), ' ', '-',) AS  Dateofbirth from tblPersonal WHERE Dateofbirth LIKE ' 0000-03-00' AND Gender = 'Male';
Posted
Updated 8-Dec-14 3:47am
v2
Comments
PIEBALDconsult 8-Dec-14 9:49am    
You didn't specify which database system you are using. Different impementations do this differently. Please use Improve question to add detail.

try..

SQL
SELECT FormattedMembershipid, Surname, Othername, REPLACE(CONVERT(NVARCHAR, Dateofbirth, 106), ' ', '-',) AS Dateofbirth from tblPersonal WHERE month(Dateofbirth)=3 AND Gender = 'Male';


see..
http://www.w3schools.com/sql/func_datepart.asp[^]
 
Share this answer
 
v2
Comments
Tomas Takac 8-Dec-14 9:58am    
+4 for complete query, but for documentation I would rather link to MSDN than to W3C schools
/\jmot 8-Dec-14 12:12pm    
thanx.
I certainly hope you are storing dates as dates and not as strings.

If this is SQL Server, look into the DATEPART function.

http://msdn.microsoft.com/en-us/library/ms174420.aspx[^]
 
Share this answer
 
v3

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