Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Location
    Recife - PE - Brazil
    Posts
    28

    Question Unanswered: Why ORDER BY isnīt working?

    Again, Hi everybody,
    I have onde table called (TB) with two fields : F1(int) and F2(varchar:10)
    In this table the field F2 is used to store dates in the format
    dd/mm/yyyy (27/12/2002). Itīs is record as varchar and undesired.
    I need to select all records from a single id from the field F1 and
    then order by the result set by date to result set be this way:


    To do this Iīm using the follow syntax :

    SELECT * FROM TB
    WHERE (F1 = '01')
    ORDER BY CONVERT(varchar(10), F2, 103)

    My problem is that the result set isnīt order by displaying as follow :


    F1 F2
    --------------------------------------
    01 05/07/1975
    01 07/01/2000
    01 12/12/1985
    01 13/12/1998
    --------------------------------------

    I need a real ordey by date to get the follow result set for this select :


    F1 F2
    --------------------------------------
    01 05/07/1975
    01 12/12/1985
    01 13/12/1998
    01 07/01/2003
    --------------------------------------
    If thereīs someone to solve this problem Iīll be thankfull

    more one time...thanks for attetion


    Leonardo Almeida

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Try this:

    SELECT * FROM TB
    WHERE (F1 = '01')
    ORDER BY cast( F2 as datetime)

  3. #3
    Join Date
    Oct 2003
    Location
    Ireland
    Posts
    54
    Why are you converting to varchar(10) and not datetime ?

    Using datetime works here on SQL 2000. What sort of collation have you ? I wonder if it can effect it

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    The best way to solve your problem is to change F2 to the datetime datatype.

    blindman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •