This is the query for sorting date.It works fine but when i adding where condition it throws error..
select date1 from (select distinct convert(varchar,convert(datetime,Date,105),103) as date1,convert(datetime,Date,103)as date2 from Tyre_StockEntry) g order by convert(datetime,convert(varchar,date1,2),103) desc Where Brand='Apollo' and Pattern='Sedan'
Error:
Incorrect syntax near the keyword 'Where'.
Can any one help me out..
Loading

Jignesh TrivediPosted Feb 24, 2014, 3:17 AM
Hi,
Good you got the solution of your problem but why you convert your filed two time in order by clause?
it will degrade your query performance as well as query may give you wrong order.
selva kumarPosted Feb 24, 2014, 1:46 AM
select date1 from (select distinct convert(varchar,convert(datetime,Date,105),103) as date1,convert(datetime,Date,103)as date2 from Tyre_StockEntry Where Brand='Apollo' and Pattern='Sedan') g order by convert(datetime,convert(varchar,date1,2),103) desc
Biswa Pujarini MohapatraPosted Feb 22, 2014, 10:41 PM
hope it helps