Sql query datediff syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KA NMC
    New Member
    • Aug 2007
    • 40

    Sql query datediff syntax error

    I know this is very simple...but the syntax is really screwing me up...Basically what I want to do is have this query check for orders that have been open two hours and more and does not have a quoted price...a small snippet of my query with out all my inner joins is:

    Code:
    select customer.customer_id_string, ordr.order_no, ordr.order_date....
    from cus... join on ...cus = ...
    where (customer.customer_id_string like '12345' and 
    datediff(hour, ordr.orderdate, getdate()) > '2')
    My syntax problem is at the datediff - this is my error
    Incorrect syntax near '>' - If I dont use > I get Incorrect syntax near ')'

    Help will be great.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    As you have posted a question in the articles section it is being moved to SQL Server forum.

    MODERATOR.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by KA NMC
      I know this is very simple...but the syntax is really screwing me up...Basically what I want to do is have this query check for orders that have been open two hours and more and does not have a quoted price...a small snippet of my query with out all my inner joins is:

      Code:
      select customer.customer_id_string, ordr.order_no, ordr.order_date....
      from cus... join on ...cus = ...
      where (customer.customer_id_string like '12345' and 
      datediff(hour, ordr.orderdate, getdate()) > '2')
      My syntax problem is at the datediff - this is my error
      Incorrect syntax near '>' - If I dont use > I get Incorrect syntax near ')'

      Help will be great.
      ...datediff(hou r... --> is this a variable? shouldn't it be @hour?...also datediff returns a numeric value and you checked it against a character.

      Comment

      • mrf12001
        New Member
        • Sep 2007
        • 1

        #4
        The correct syntax would be as follows

        datediff(hour, ordr.orderdate, getdate()) > 2)

        Comment

        • KA NMC
          New Member
          • Aug 2007
          • 40

          #5
          Thanks for all the help...its always the simple things that get ya for hours....

          Comment

          Working...