• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Unusual Database Query

Guest
Jul 18, 2006 Jul 18, 2006

Copy link to clipboard

Copied

I need to add a new function to my search facility. At the moment, users are able to display records alphabetically - they click on A,B,C etc etc and my query looks for all records that begin with that letter, like so -

WHERE company_name LIKE '%A'

etc

One thing I don't currently have is the ability for people to look for anything that begins with a number. I could be lazy and list numbers 0,1,2,3 etc - but given that there will be few results anyway, and it looks nicer, I'd like to have the link as '0-9'

So, my question is - how to a perform a query to return all records that begin with a number?

I'd appreciate any help on this - suffering major brain freeze on this at the moment!
TOPICS
Advanced techniques

Views

296

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 18, 2006 Jul 18, 2006
where substr(yourfield, 1, 1) in ('0', '1', '2', ... '9')

syntax is database specific but most if not all the common ones have string functions.

Votes

Translate

Translate
LEGEND ,
Jul 18, 2006 Jul 18, 2006

Copy link to clipboard

Copied

where substr(yourfield, 1, 1) in ('0', '1', '2', ... '9')

syntax is database specific but most if not all the common ones have string functions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 18, 2006 Jul 18, 2006

Copy link to clipboard

Copied

Thanks for the super-quick reply Dan, thats answered my question perfectly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 19, 2006 Jul 19, 2006

Copy link to clipboard

Copied

LATEST
This will work in SQL Server:

select company_name
from table1
where ISNUMERIC(SUBSTRING(company_name,1,1)) = 1

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation