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 2005 Forums
 Transact-SQL (2005)
 Where clause question

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-07-03 : 09:21:05
What am I doing wrong that's not bringing back my where clause? I am getting other records as well but only want the ones specified below.

select * FROM diaries1
where (diarycode1 = '9W' or diarycode1 = '5W' or diarycode1='7W')
or (diarycode2 = '9W' or diarycode2='5W'or diarycode2='7W')
or (diarycode3 = '9W' or diarycode3 = '5W' or diarycode3='7W')

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-03 : 09:23:56
can you show us some test data and illustrate which records you do / don't want to be returned?

Em
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-07-03 : 09:28:45
After executing the where clause I get this data in the DiaryDTE1 field:

DIARYDTE1
9W
9W
2E
MR
MR
5W
JR
JR
7W
7W

I only want 5W, 7W and 9W
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-03 : 09:31:40
hmmm.... do you actually want....?


where diarycode1 in ('9W','5W','7W')
and diarycode2 in ('9W','5W','7W')
and diarycode3 in ('9W','5W','7W')


if not, show more test data with the other column combinations too

Em
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-07-03 : 10:02:43
Yes that's what I want to get back.
Go to Top of Page
   

- Advertisement -