Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Items by specific letter or higher

Status
Not open for further replies.

Moebius01

Programmer
Oct 27, 2000
309
US
I was working on a small project and came across this idea, but wasn't sure if it was doable.

Is there a way to select items that start with a given letter or higher? For example,

select * from table where LOWER(item) LIKE 'g%'

would give me all items starting with the letter g. However, what if I needed to simply start at g and pull all items that start with g - z? Is there an easy way to do this that my fried brain is overlooking?
 
Sratch that. My brain came online shortly after posting and used a quick conversion to ASCII to do the job.

 
why convert ? simply write
Code:
select * from table where LOWER(item) >= 'g' ;



[ponder]
----------------
ur feedback is a very welcome desire
 
perhaps

select * from table where LOWER(substr(item,0,1)) >= 'g' ;

is better then or is 'aa' not greater then 'g'

 
Strange, when I tried the >= the first time it didn't seem to work, so I went with the ASCII. Guess I'll give that another go. Must have been another typo in the statement that caused nothing to return.

 
accoring to my knowledge string comaprison is ascii values and in our case comes to lexicographic. also each char of 1st string is matched with corresponding char of 2nd string. hence 'aa' is smaller than 'g' in dict order but grater length wise.

If length is the criteria then ur optin is a better method and i comaprison is cii based then mine wold work equally well



[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top