Groups | Blog | Home
all groups > sql server mseq > march 2005 >

sql server mseq : Help with Where clause


Newbie
3/17/2005 10:09:21 AM
Hi,

I want to return records based on a linetype and classtype

Here is what I have so far
Where (LineType = '1' OR LineType = '7')
or (LineType = '5'AND ClassType NOT LIKE '[_]%')

I am trying to return all LineType 1 and 7 and only LineType 5 where the
classtype does not start with an underscore but the above syntax doesn't
return any records where the ClassType starts with an underscore regardless
of whether they are LineType 1, 7 or 5

How can I achieve my goal?

Thanks

Hugo Kornelis
3/17/2005 1:34:04 PM
[quoted text, click to view]

Hi Newbie,

I'm sorry, but I could not reproduce the behaviour you're reporting. Run
the following script in Query Analyzer and check the results:

create table test(LineType char(1) not null, ClassType char(3) not null)
go
insert test select '1', '_as' union all select '1', 'dfg'
union all select '5', '_as' union all select '5', 'dfg'
union all select '7', '_as' union all select '7', 'dfg'
union all select '8', '_as' union all select '8', 'dfg'
go
select * from test
Where (LineType = '1' OR LineType = '7')
or (LineType = '5'AND ClassType NOT LIKE '[_]%')
go
drop table test
go

Results on my test database:

LineType ClassType
-------- ---------
1 _as
1 dfg
5 dfg
7 _as
7 dfg

If you have different results, then please paste the output of
SELECT @@VERSION
in a reply to this message.

If you have the same results, then it must be something else. Please
post a simple script (as I did above) that allows me to reproduce the
behaviour. Include the expected output as well. (www.aspfaq.com/5006)

Best, Hugo
--

Newbie
3/17/2005 4:53:30 PM
Thanks _ I tried your script and it worked fine - the problem was my working
of the calculator - managed to make the same mistake more than once!

Thanks again
[quoted text, click to view]

AddThis Social Bookmark Button