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

Checking to see if a word starts with a number..SQL

LEGEND ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

I have a list of companies for my work. Some start with numbers. I created a
sorting that looks for the first letter. Works great for A-Z, but I don't
know how to do it for 0-9. Can't compare a varchar against an int. I tried
this, but didn't work. Any ideas?

WHERE UPPER(Left(ORG_NAME_1,1)) IN ('0','1','2','3','4','5','6','7','8',9')


TOPICS
Advanced techniques

Views

461

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
Participant ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

If thats Oracle you're using check out the CAST function... if its not then there should be a similar function in whatever you're using.

Also, no need to use UPPER if youre looking for a number.

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
LEGEND ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

you can save yourself some typing by using the between keyword.

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
Advocate ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

can you still use the between keyword if you are casting the integers as varchar fields?

Just out of curiosity, what sort of sorting are you doing that you can't get away with a simple ORDER BY clause (since that sorts on first letter anyway and will handle leading digits as well)?

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
LEGEND ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

quote:

Originally posted by: insuractive
can you still use the between keyword if you are casting the integers as varchar fields?

I see no need to cast as integers. Between '0' and '9' gives the same answer as between 0 and 9.

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
LEGEND ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

That way my question I was thinking.

I am using MSSQL


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
Advocate ,
Apr 04, 2007 Apr 04, 2007

Copy link to clipboard

Copied

Why don't you explain a little more about the type of sort you are trying to do, and why you can't use "ORDER BY ORG_NAME" in your SQL statement

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
LEGEND ,
Apr 19, 2007 Apr 19, 2007

Copy link to clipboard

Copied

LATEST
Its not a sort I was attempting to do. I wanted to only show the companys
that begin with an A, then a B, then a C, etc. However, I was having an
issue with those that began with numbers (0-9). It has been solved well.


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