Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Is this a proper way to use or condition

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2015-01-26 : 12:47:53
I have the select query with where condition has Or clause does fiscal_year and R_status apply to Or clause account condition.
or should i use again fiscal year and r_status with or clause condtion at the bottom.


WHERE FISCAL_YEAR = 2014
AND ACCOUNT BETWEEN 8000 AND 8999 and R_STATUS in(1,9)
or ACCOUNT BETWEEN 3000 AND 3500

Thanks a lot for the helpful info.


Ifor
Aged Yak Warrior

700 Posts

Posted - 2015-01-26 : 13:09:49
What you have amounts to:

WHERE
(
FISCAL_YEAR = 2014
AND R_STATUS IN (1, 9)
AND ACCOUNT BETWEEN 8000 AND 8999
)
OR ACCOUNT BETWEEN 3000 AND 3500;

I suspect you want:

WHERE FISCAL_YEAR = 2014
AND R_STATUS IN (1, 9)
AND
(
ACCOUNT BETWEEN 8000 AND 8999
OR ACCOUNT BETWEEN 3000 AND 3500
);


See:
https://technet.microsoft.com/en-gb/library/ms186992(v=sql.105).aspx
Go to Top of Page
   

- Advertisement -