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..
How to solve this error?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 22, 2014, 5:41 PM EST
hope it helps
selva kumarRank #2,987 · 483 reputationPosted Feb 23, 2014, 8:46 PM EST
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 23, 2014, 10:17 PM EST
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.