here is my sample code
create table [sample](T_id int identity(1,1),date varchar(50));
04-05-2013
07-03-2013
10-01-2013
20-08-2013
18-02-2013
09-07-2013
07-06-2013
05-12-2013
05-12-2013
05-12-2013
i want to sort the date based on DD-MM-YYYY fomat:
i m using below query
select distinct convert(varchar,date,103),convert(datetime,date,103)as date from [sample] order by date desc;
i m getting below output,
[no column name] date
05-12-2013 2013-12-05 00:00:00.000
20-08-2013 2013-08-20 00:00:00.000
09-07-2013 2013-07-09 00:00:00.000
07-06-2013 2013-06-07 00:00:00.000
04-05-2013 2013-05-04 00:00:00.000
07-03-2013 2013-03-07 00:00:00.000
18-02-2013 2013-02-18 00:00:00.000
10-01-2013 2013-01-10 00:00:00.000
how do i get the column name for fist one...? can anyone help my question..
Loading


Hari Bharadwaj Vangala19 reputationPosted May 16, 2013, 10:40 PM EDT
Use the same "as" for first column, like u used in second. Hope this was expected answer.
Hope this helps..
selva kumarRank #2,987 · 483 reputationPosted May 16, 2013, 10:54 PM EDT
Pankaj PandeyRank #642 · 3.7K reputationPosted May 16, 2013, 11:14 PM EDT
hiiii,
select convert(varchar,getdate(),103) as Date_varchar,convert(datetime,getdate(),103)as Date_datefrom [sample] order by date desc;
mark as answered if helpful
selva kumarRank #2,987 · 483 reputationPosted May 16, 2013, 11:28 PM EDT
select distinct convert(varchar,date,103)as date,convert(datetime,date,103)as date1 from [sample] order by date desc;
this is my query. if i m using this...
i m getting two columns.....like this...
date1 date
05-12-2013 2013-12-05 00:00:00.000
20-08-2013 2013-08-20 00:00:00.000
09-07-2013 2013-07-09 00:00:00.000
07-06-2013 2013-06-07 00:00:00.000
04-05-2013 2013-05-04 00:00:00.000
07-03-2013 2013-03-07 00:00:00.000
18-02-2013 2013-02-18 00:00:00.000
10-01-2013 2013-01-10 00:00:00.000
i want to display first column........
Hari Bharadwaj Vangala19 reputationPosted May 17, 2013, 12:43 AM EDT
order by date1 desc;
This will work perfectly...
Pankaj PandeyRank #642 · 3.7K reputationPosted May 17, 2013, 1:43 AM EDT
order by date1 desc;
selva kumarRank #2,987 · 483 reputationPosted May 17, 2013, 1:48 AM EDT
20-08-2013
18-02-2013
10-01-2013
09-07-2013
07-06-2013
07-03-2013
05-12-2013
04-05-2013
but i am expecting like this; sorting based on month vice....
05-12-2013
20-08-2013
09-07-2013
07-06-2013
04-05-2013
07-03-2013
18-02-2013
10-01-2013
tell me another way.....
Hari Bharadwaj Vangala19 reputationPosted May 17, 2013, 3:18 AM EDT
You should declare ur date1 also as datetime then u can use the feature as present in above link...
If u declare ur date 1 as datetime then u get the above expected result...
select date1 from
(select distinct convert(datetime,date,103) as date1,convert(datetime,date,103)as date2 from [sample])t
order by MONTH(date1) desc
Please convert the o/p in the design page while u display.Hope this helps....refining my knowledge:P...tq.
selva kumarRank #2,987 · 483 reputationPosted May 17, 2013, 5:13 AM EDT
i want to display DD-MM-YYYY... tell me another way......