Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone,

i am writing a sql query in which i am using cast keyword to make a datetime value to date only.
now i want to use a order by clause in the same query.
so where i should use it?

actly if i am not using order by then months are coming as february first then january.
i want january first and then february.

my code is
SELECT DISTINCT convert(NVARCHAR(50),cast(FTA_Date AS DATETIME),103) FROM FTA_Report 



thanks,
rumki...
Posted
Updated 8-Mar-11 19:07pm
v4
Comments
Albin Abel 9-Mar-11 0:56am    
at the end of this query

1 solution

SQL
Select FTADATE from (SELECT DISTINCT convert(NVARCHAR(50),cast(FTA_Date AS DATETIME),103) FTADATE FROM FTA_Report) T ORDER BY CAST(FTADATE AS DATETIME)
 
Share this answer
 
v2
Comments
debalina2 9-Mar-11 1:01am    
dear friend if i run this query then it is showing this error.

ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Prerak Patel 9-Mar-11 1:12am    
I updated the answer. Try it now.
debalina2 9-Mar-11 2:02am    
this is the exact solution.
Thanks a lot Prerak.
Prerak Patel 9-Mar-11 2:04am    
You are welcome.

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