MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 6th, 2004, 10:07 AM
Nina :) Nina :) is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 Nina :) User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Problems with complex query...

Hi,

I am new to this forum and hope there is somebody how has some time to help me here... really struggling....

this is my query:
<<

select * from privuser.actvcode
where
(actv_code_type_id = 205) and (short_name = 1)

(or (actv_code_type_id = 214) and (short_name not like 'JNP'))

(or (actv_code_type_id = 215) and (short_name not like 'SUB'))

(or (actv_code_type_id = 218) and (short_name not like '57%'))

(or (actv_code_type_id = 218) and (short_name not like '58%'))
>>>

I am trying to query the same two columns with different combination of values... hmm..

Many Thanks,
Nina

Reply With Quote
  #2  
Old July 6th, 2004, 12:16 PM
lucasalexander lucasalexander is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Atlanta
Posts: 39 lucasalexander User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to lucasalexander Send a message via MSN to lucasalexander
Try moving the "or"s outside the parentheses like so:

select * from privuser.actvcode
where
((actv_code_type_id = 205) and (short_name = 1))
or ((actv_code_type_id = 214) and (short_name not like 'JNP'))
or ((actv_code_type_id = 215) and (short_name not like 'SUB'))
or ((actv_code_type_id = 218) and (short_name not like '57%'))
or ((actv_code_type_id = 218) and (short_name not like '58%'))

Lucas Alexander
http://www.alexanderdevelopment.net

Reply With Quote
  #3  
Old July 7th, 2004, 07:51 AM
Nina :) Nina :) is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 Nina :) User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
still no joy..

thank you Lucas!

Still no joy though.. The query is executing and gives me a result set, but it contains values i wish to exclude.

I want to include actv_code_type_id = 214, but not short_name like 'JNP'

any other good suggestions?

Nina

Reply With Quote
  #4  
Old July 7th, 2004, 10:57 AM
brchris brchris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 brchris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Is short_name a string or a number? You seem to have it defined both ways. Not sure if that is an issue worth checking or not.

Also, start with the simpliest of filters if complex filters are causing problems until you have an expected resulting set. Then add filters as you go along making sure your resulting set is still expected, until you have your finished filter.

I can't see anything first off except the differing variable type. Also, if you are getting more than one record that is not expected what are those records. It is easier to visualize what a computer is thinking when you see the unexpected results.

Reply With Quote
  #5  
Old July 9th, 2004, 09:37 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
does that shortname "jnp" show up for actv_code_type_id = 214?...or is it showing up for another actv_code_type_id?

Reply With Quote
  #6  
Old July 10th, 2004, 07:22 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,921 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 58 m 55 sec
Reputation Power: 1022
the last two conditions are problematic

or ((actv_code_type_id = 218) and (short_name not like '57%'))
or ((actv_code_type_id = 218) and (short_name not like '58%'))

all rows with actv_code_type_id = 218 will be accepted

the short name will either be not like one value or not like the other

__________________
r937.com | rudy.ca

Reply With Quote
  #7  
Old July 11th, 2004, 01:00 PM
Nina :) Nina :) is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 Nina :) User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Still not working propertly..

Thank you very much for feedback!

The short_name is varchar 60, and are containing a mix of numbers and letters. Unfortunatly this are a external db and can not be changed either.

I do understand that the two queries short_name 58% nad 57% will not work. What I really want is the range from 57% to 58%, but I don't think this is not possible since it is varchar...


"jnp" is showing up where actv_code_type_id = 214

hmm...

Nina

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Problems with complex query...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT