locked
SqlDataSource having issues using or in the where statements RRS feed

  • Question

  • User475570419 posted

    Hello,

    I am having trouble with my Sqldatasource with using OR statements in the Where Clause.  It will not work using the OR. Below is my sql statement:

    SELECT [OSVer], [DiskFree], [DiskSize], [MemorySize], [Asset], [IPAddress], [LoggedOnUser], [RPTSendTime]

    FROM [Units_Archive]

    WHERE (([LoggedOnUser] = @LoggedOnUser) or ([MachineName] = @MachineName) and ([RptSendTime] between (@RptSendTime) AND (@RptSendTime2)))

    Order by RPTSendTime

    Any help would be greatly appreciated.

    Bob

    Wednesday, June 6, 2018 1:58 PM

Answers

  • User-1716253493 posted
    WHERE ([LoggedOnUser] = @LoggedOnUser or [MachineName] = @MachineName) 
    and [RptSendTime] between @RptSendTime) AND @RptSendTime2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 6, 2018 9:14 PM

All replies

  • User753101303 posted

    Hi,

    not work

    That is ? Do you have an error message or the query just doesn't return any row at all? I would test the query in my database with the same values to see how it behaves. Are you 100% sure this query runs with the expected values ?

    For example user names and machine names are normalized to always include (or exclude if you prefer) the domain name ???

    If you still can't find trhe problem, simplify the query to find which criteria is causing your query to return no result at all.

    Wednesday, June 6, 2018 2:35 PM
  • User-1716253493 posted
    WHERE ([LoggedOnUser] = @LoggedOnUser or [MachineName] = @MachineName) 
    and [RptSendTime] between @RptSendTime) AND @RptSendTime2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 6, 2018 9:14 PM
  • User475570419 posted

    Thank you oned_gk.  That worked.  I appreciate your help.

    Thursday, June 7, 2018 12:08 PM
  • User753101303 posted

    Ah great. I missed it was just a parenthesis issue. I would suggest to not use more parenthesis than needed for clarity.

    Thursday, June 7, 2018 12:18 PM