Friday, February 24, 2012

Help with Where clause

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
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)
|||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@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:d5ui31d2np1k5khvonabvmbcdmpr1lollf@.4ax.com...
> On Thu, 17 Mar 2005 10:09:21 -0000, Newbie wrote:
>
> 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)

No comments:

Post a Comment