Avatar of Ernesto
Ernesto
Flag for Mexico asked on

achive a distinct with convert involved

hi all
how can achive this query?


select distinct fechap from cheque  order by Convert(Datetime, fechap, 103)desc

is a varchar that i need to convert in date to sort

tsm
Microsoft SQL ServerVisual Basic.NETSQL

Avatar of undefined
Last Comment
Anthony Perkins

8/22/2022 - Mon
Nasir Razzaq

And is it not working? You need a space between ")" and "desc"
Ernesto

ASKER
has it

tsm
Nasir Razzaq

and...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Ernesto

ASKER
any way to achive it?
Ernesto

ASKER
do not work
Nasir Razzaq

You get any error?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ernesto

ASKER
Cuando se especifica SELECT DISTINCT, los elementos de ORDER BY deben aparecer en la lista de selección.

when an select distinct is specified, the elements of the order by must appear in the list
Ernesto

ASKER
any advice?
tsm
Nasir Razzaq

Try

select distinct Convert(Datetime, fechap, 103) from cheque  order by Convert(Datetime, fechap, 103) desc
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Anthony Perkins

edo60,

While most of us here have a lot of knowledge with SQL Server, none of us (to my knowledge) can read a crystal ball, so it is in your best interest to explain fully what you need as we are not sitting in front of your computer.  Quite frankly, stating "do not work" is no use whatsoever.  Just imagine taking your car to the mechanic telling them "do not work" and I suspect you should understand.

For clarity here is the same in Spanish:
Mientras hay muchos aquí que son muy capaces usando SQL Server, nadie (de que yo sepa) somos magos, por lo tanto por tu bien te conviene explicar completamente tus requerimientos ya que no estamos enfrente de tu computadora (ordenador).  Francamente diciendo "no funciona" no ayuda en lo más mínimo.  Imagina que lleves tu auto al mecánico y le dices" "no funciona" y creo que comprenderás.
ASKER CERTIFIED SOLUTION
Anthony Perkins

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ernesto

ASKER
Ok, im understand what you say, sorry for the language barrear, but you give me greate solution with

SELECT      DISTINCT
        CONVERT(Datetime, c.fechap, 103) fechap
FROM    cheque c
ORDER BY
      fechap DESC

it give me the result that i want, only i detail, is any way to put off the time?
the result is:

2013-01-04 00:00:00.000
2013-01-03 00:00:00.000
2013-01-02 00:00:00.000
2012-12-21 00:00:00.000
2012-12-19 00:00:00.000
2012-12-18 00:00:00.000
2012-12-13 00:00:00.000
2012-12-11 00:00:00.000

is the order that i need but is posible to put off 00:00:00.000?
tsm
regards
Ernesto

ASKER
tsm
regards
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Anthony Perkins

If you have SQL Server 2008 you can do this:
CONVERT(Date, c.fechap, 103) fechap

If not you can do this (just understand that it is now character data):
CONVERT(char(10), CONVERT(Datetime, c.fechap, 103), 120) fechap