query with OR in where clause

  • i have a query

    select name, name2, type, date, status from table1

    where (name = '' or name <>name2) and status =0

    but, ssrs is converting this query automatically to

    select name, name2, type, date, status from table1

    where name = '' and status =0 or name <>name2 and status =0

    this is giving wrong results... the reason is brackets are missing in operands..the correct way could be

    select name, name2, type, date, status from table1

    where (name = '' and status =0 ) or (name <>name2 and status =0)

    how to solve this ??

  • What about making it into a stored procedure and then making the call to that? That would absolutely fix the issue.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • stored procedures is an alternative...but i am concerned why query is doing this on its own..

    even when i write is corretly and save...its saving its own way.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply