Professional Web Applications Themes

SQL Statement question - Microsoft SQL / MS SQL Server

I need to perform an SQL query a bit like this SELECT * FROM Table ORDER BY ((DateField-AnotherDateField) < GetDate()) Any Ideas how to do this. Trying it in the format above throws a problem because of the <. I think I may have to put some kind of IF or IIF statement in, but how?...

  1. #1

    Default SQL Statement question

    I need to perform an SQL query a bit like this

    SELECT *
    FROM Table
    ORDER BY ((DateField-AnotherDateField) < GetDate())

    Any Ideas how to do this. Trying it in the format above throws a problem
    because of the <.

    I think I may have to put some kind of IF or IIF statement in, but how?


    Tim Guest

  2. #2

    Default SQL Statement question

    Hello,

    Can you give is a bit more detail on what you are trying
    to acplish

    Peter

     
    throws a problem 
    statement in, but how? 
    Peter Guest

  3. #3

    Default Re: SQL Statement question


    "Tomislav Kralj" <tel.hr> wrote in message
    news:phx.gbl... 

    Thanks. That is exactly what I am doing. I have no idea why I did not think
    of it. Perhaps because today is <smug grin> the last day before my vacation.
    </smug grin>

    Thanks for kick starting the ol' brain.
     
    >
    >[/ref]


    Tim Guest

  4. #4

    Default Re: SQL Statement question


    "Peter" <co.uk> wrote in message
    news:09cc01c34c54$230b1ac0$gbl... 

    To order by a boolean result of an operation.

    Tomislav got it right though. I am using a case statement.
     
    > throws a problem 
    > statement in, but how? [/ref]


    Tim Guest

  5. #5

    Default Re: SQL Statement question

    You don't need to use CASE to do this. GETDATE() is redundant in ORDER BY
    (because it doesn't change). Use:

    ORDER BY DATEDIFF(DAY,AnotherDateField,DateField)

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --



    David Guest

  6. #6

    Default Re: SQL Statement question


    "David Portas" <org> wrote in message
    news:phx.gbl... 

    Excellent. Even better thanks
     


    Tim Guest

Similar Threads

  1. question about DELETE statement
    By Walter in forum ASP Database
    Replies: 8
    Last Post: September 9th, 06:18 AM
  2. If statement question
    By Smriti Dev in forum PHP Development
    Replies: 3
    Last Post: December 8th, 11:12 PM
  3. real if then statement question.
    By aoninja webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 0
    Last Post: October 25th, 04:51 AM
  4. SQL statement question
    By Jason Reljac in forum PHP Development
    Replies: 2
    Last Post: July 20th, 06:06 AM
  5. Select Statement Question (Again)
    By Largo SQL Tools in forum Microsoft SQL / MS SQL Server
    Replies: 9
    Last Post: July 14th, 05:02 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139