Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

query with OR in where clause Expand / Collapse
Author
Message
Posted Saturday, September 18, 2010 2:15 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 27, 2013 2:48 AM
Points: 14, Visits: 26
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 ??
Post #988702
Posted Monday, September 20, 2010 9:09 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 7:03 AM
Points: 15,738, Visits: 28,146
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #989470
Posted Tuesday, September 21, 2010 12:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 27, 2013 2:48 AM
Points: 14, Visits: 26
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.
Post #989977
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse