Click here to Skip to main content
15,881,644 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
i have one column in database that is DOB(Date of Birth)

in that database all employee details of DOB has inserted records are there.

DOB(Date of birth format as mm/dd/yyyy)

Example as follows;

DOB( IN Database DOB has name like that) Format as mm/dd/yyyy)

9/16/1945
4/10/1952
6/30/1978
4/19/1981
4/5/44
4/11/1948
3/12/77
12/13/1985
6/14/1974
1/3/1944
8/7/1950
11/5/1977
8/11/1974
2/16/1941
7/23/1944
7/23/1968
3/7/1974
6/27/1945
11/3/1952
4/10/1976
3/29/1987
11/2/1956
12/14/1987
5/29/1989
9/24/1973
10/26/1978
9/25/2001
5/1/1984
8/4/1977
10/21/2008

i want the output as MONTH to be arranged in Ascending Order All Months.
From January to Decmeber in Ascending Order.

for that how to write the query.

SQL
"select Name, CONVERT(varchar(11), DOB, 106)  AS Date_of_birth,Mobileno as Mobile_Number, CONVERT(varchar(11), Weddingday, 106) AS Wedding_Day,EMail as E_Mail from BirthDayWish where Active = 'A' ORDER BY Name";


from the above query how to write the Month to be Displayed in ascending order.
Posted
Updated 2-Jan-13 17:14pm
v2

Hi,

SQL
select Name,DateName(Month,DOB) MonthName, CONVERT(varchar(11), DOB, 106)  AS Date_of_birth,Mobileno as Mobile_Number, CONVERT(varchar(11), Weddingday, 106) AS Wedding_Day,EMail as E_Mail from BirthDayWish where Active = 'A' ORDER BY Month(DOB), Name



This will work...
 
Share this answer
 
v2
Try this

SQL
SELECT Name, CONVERT(VARCHAR(11), DOB, 106) AS Date_of_birth,Mobileno AS Mobile_Number, CONVERT(VARCHAR(11), Weddingday, 106) AS Wedding_Day,EMail AS E_Mail
FROM BirthDayWish
WHERE Active = 'A'
ORDER BY MONTH(DOB),DAY(DOB),YEAR(DOB)
 
Share this answer
 
Comments
Tharaka MTR 6-Jan-13 8:28am    
Could you please let me know why you guys are down voted my query? if this is not working I'm OK for that. But I'm pretty sure this is working well.
Hi,

Try the following,

To sort, Instead of year only by month use the following,

Select CONVERT(varchar(11),d.dob,106), DATENAME(MONTH,d.dob), DATEPART(MONTH,d.dob) from driver d order by DATEPART(MONTH,d.dob) asc


To sort by year, date and month use the following,

Select CONVERT(varchar(11),d.dob,106), DATENAME(MONTH,d.dob), DATEPART(MONTH,d.dob) from driver d order by d.dob asc
 
Share this answer
 
try this.
SQL
select Name, CONVERT(varchar(11), DOB, 106) AS Date_of_birth,Mobileno as Mobile_Number, CONVERT(varchar(11), Weddingday, 106) AS Wedding_Day,EMail as E_Mail from BirthDayWish where Active = 'A'
ORDER BY MONTH(Date_of_birth)
 
Share this answer
 
v3
Comments
Tharaka MTR 2-Jan-13 8:26am    
This query will not work. see following section

= 'A' ORDER BY Name
ORDER BY MONTH(Date_of_birth)

modify it as

= 'A' ORDER BY Name, MONTH(Date_of_birth)
Use This:

SQL
SELECT  *
FROM         tbl_userwritereviews
ORDER BY DATEPART(mm, date)
 
Share this answer
 
add DATENAME(month, DOB) AS 'Birth Month' and they do an order by month(DOB) ( month returns a number, datename would give you months alphabetically )
 
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