Results 1 to 2 of 2

Thread: Statement return error

  1. #1
    Elena Guest

    Statement return error

    Hi!
    I want to select just 1 day older rows from table.
    I run next statement:

    select*from report
    where Date = ltrim (DATEPART (dd,GETDATE())>1)+'/'+
    ltrim (DATEPART(mm,GETDATE()))+'/'+ltrim (DATEPART(yyyy, GETDATE()))

    the datetime in the column Date is: dd/mm/yyyy

    and here is error message:

    Server: Msg 170, Level 15, State 1, Line 2
    Line 2: Incorrect syntax near '>'.

    I tried everything , but can't get rid of this error message.
    Please help!



  2. #2
    Steve Guest

    Statement return error (reply)


    I believe one of these is the solution you are looking for:

    If the Date column is a datetime datatype this would be an easier solution:

    select * from report
    where DATEDIFF(dd, Date, GETDATE()) = 1

    Else use this modifcation to your current statement:

    select * from report
    where Date = LTRIM(DATEPART(dd, GETDATE()) + 1) + '/' +
    LTRIM(DATEPART(mm, GETDATE()))+ '/' + LTRIM(DATEPART(yyyy, GETDATE()))

    Steve

    ------------
    Elena at 1/12/00 11:31:34 AM

    Hi!
    I want to select just 1 day older rows from table.
    I run next statement:

    select*from report
    where Date = ltrim (DATEPART (dd,GETDATE())>1)+'/'+
    ltrim (DATEPART(mm,GETDATE()))+'/'+ltrim (DATEPART(yyyy, GETDATE()))

    the datetime in the column Date is: dd/mm/yyyy

    and here is error message:

    Server: Msg 170, Level 15, State 1, Line 2
    Line 2: Incorrect syntax near '>'.

    I tried everything , but can't get rid of this error message.
    Please help!



Posting Permissions

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