dbTalk Databases Forums  

Help with Where clause

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss Help with Where clause in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Newbie
 
Posts: n/a

Default Help with Where clause - 03-17-2005 , 04:09 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



Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Help with Where clause - 03-17-2005 , 06:34 AM






On Thu, 17 Mar 2005 10:09:21 -0000, Newbie wrote:

Quote:
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

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
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Reply With Quote
  #3  
Old   
Newbie
 
Posts: n/a

Default Re: Help with Where clause - 03-17-2005 , 10:53 AM



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
"Hugo Kornelis" <hugo (AT) pe_NO_rFact (DOT) in_SPAM_fo> wrote

Quote:
On Thu, 17 Mar 2005 10:09:21 -0000, Newbie wrote:

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


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
--

(Remove _NO_ and _SPAM_ to get my e-mail address)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.