If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL to find if field is low values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-30-07, 12:12
Pattio Pattio is offline
Registered User
 
Join Date: May 2007
Posts: 2
SQL to find if field is low values

I need assistance with a field in the first five positions is low-values and then has either spaces or values -- I need to get the ones where only the first 5 positions are low values?
Reply With Quote
  #2 (permalink)  
Old 05-30-07, 12:40
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Fancy posting some example data and what your expect your results to look like?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 05-30-07, 12:53
Pattio Pattio is offline
Registered User
 
Join Date: May 2007
Posts: 2
Here is an example of the data in column addr1 pic x(20):

123 Cannon Way
X'0000000000' Nasco place
X'0000000000' Yellow Rd
456 Jamison Ave

In my select I want to get the 2 & 3 data example in my select, when i put the following SQL

Select addr1
,addr2
From TWIP120
Where addr1 = X'00'

I don't get rows 2 & 3 back because my whole data field isn't low values

Last edited by Pattio; 05-30-07 at 12:57.
Reply With Quote
  #4 (permalink)  
Old 05-30-07, 13:35
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I'm lost in translation...
Code:
Where addr1 = X'00'
This isn't valid SQL.
And what do you mean by "low values"
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 06-02-07, 22:01
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by Pattio
I need assistance with a field in the first five positions is low-values and then has either spaces or values -- I need to get the ones where only the first 5 positions are low values?
The syntax varies depending on the SQL dialect... What vendor (DB2, Oracle, Microsoft, MySQL, etc) and version (1.2, 10.5, Rockafeller, Tornado, etc) of SQL are you using?

-PatP
Reply With Quote
  #6 (permalink)  
Old 06-10-07, 16:43
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by Pattio
Select ...
From TWIP120
Where addr1 = X'00'

I don't get rows 2 & 3 back because my whole data field isn't low alues
What about
Code:
Select ...
     From TWIP120 
   Where substr(addr1, 1, 5) = X'00'
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #7 (permalink)  
Old 06-11-07, 03:42
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
Select ...
     From TWIP120 
   Where substr(addr1, 1, 5) = X'00'
Won't you hit syntax errors with the single quotes?
__________________
George
Twitter | Blog
Reply With Quote
  #8 (permalink)  
Old 06-11-07, 05:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
SUBSTR isn't standard sql either
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 06-11-07, 05:27
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Change to a LIKE comparison?
__________________
George
Twitter | Blog
Reply With Quote
  #10 (permalink)  
Old 06-11-07, 15:04
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Still a bit platform-specific, but instead of asking for 'equal to "LOW VALUES"' one could maybe ask for 'smaller than any normal text'.
When the underlying system uses ASCII or UNICODE, and assuming no ASCII values between 1 and 31 are present as first character of the addr1 field, the following would give the wanted rows:
Code:
Select ...
     From TWIP120 
   Where addr1 < ' '
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On