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 2000 Forums
 SQL Server Development (2000)
 and/or confused me

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-10-04 : 14:58:27
How to use AND/OR is confused me. For example, I want to:

1) do select statement: AAA = "select * from Order"
2) where statement: "OrderID = 123"
3) where statement: "OrderCity = New York"

I want to get result like:

(select * from Order where OrderID = 123) or (select * from Order where OrderCity = 'New York')

Can I write it like:

select * from Order where OrderID = 123 or OrderCity = 'New York'



Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-10-04 : 15:00:18
did you try it??

the answer is Yes you can do that...

Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2005-10-04 : 15:11:46
Make more. If I want result like:
(select * from Order where OrderID = 123 and OrederDt= '3/10/2005') or (select * from Order where OrderCity = 'New York' and OrderDt = '3/10/2005)

Can I write it like:

select * from Order where OrderID = 123 and OrederDt= '3/10/2005' or OrderCity = 'New York'
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-10-04 : 15:36:33
Again, YES. Did you try it?

You need to use parenthesis, though, to seperate the two conditions so that it is clear; i.e., as you wrote your expression, it can be interpretted as

where OrderID = 123 and (OrederDt= '3/10/2005' or OrderCity = 'New York')

or

where (OrderID = 123 and OrederDt= '3/10/2005') or OrderCity = 'New York'


which have two very different meanings. *Always* use parenthesis () to explicitly indicate what you want when you mix AND's and OR's in your boolean expressions.
Go to Top of Page
   

- Advertisement -