Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
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.
 
"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 1-Jan-13 21:22pm
Edited 2-Jan-13 18:14pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 )
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use This:
 
SELECT  *
FROM         tbl_userwritereviews
ORDER BY DATEPART(mm, date)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this.
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)
  Permalink  
v3
Comments
Tharaka MTR at 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)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Hi,
 
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...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Try this
 
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)
  Permalink  
Comments
Tharaka MTR at 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100