Solved

SQL Query For Alpha or Numerical Characters

Posted on 2003-11-26
9
1,417 Views
Last Modified: 2011-04-14
Hello,
I have a column in my database called 'Atozlisting', it is filled with only i character in each row of data.  the character maybe an alpha character or a Numeral.  i.e
a or g or f or 5 or 3 or j... etc

I'm trying to write two SQL statements.  The first one will return only records that have an alpha characters as their value and the second one will return records that have a numerals as their value

thanks
:-)
0
Comment
Question by:show_t
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:lausz
ID: 9825063
Try this

All together

select case when isnumeric(Atozlisting) = 1 then 'Num' else 'alpha' end
from yourtable

or

Select Atozlisting  --numeric
from yourtable
where isnumeric(Atozlisting) = 1

and

Select Atozlisting -- alpha
from yourtable
where isnumeric(Atozlisting) = 0
0
 

Author Comment

by:show_t
ID: 9825358
thanks for your help,

i've also tried adding 'DISTINCT' in the SQL query in an attempt to NOT return any records with the same values but this doesn't work.  is 'distinct' only used with joins ?

thanks again
0
 
LVL 6

Expert Comment

by:lausz
ID: 9826072
This must work.

Select distinct Atozlisting -- alpha
from yourtable
where isnumeric(Atozlisting) = 0


0
 

Author Comment

by:show_t
ID: 9826227
Yeah it works just fine, i just wanted to know if you also knew how to NOT return records that have the same value

Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:lausz
ID: 9826654
Do you need more help ?
0
 

Author Comment

by:show_t
ID: 9827842
yes please, about the 'Distinct' issue
0
 
LVL 6

Expert Comment

by:lausz
ID: 9831269
Can you post your final query...(with the distinct not running) ?
0
 

Author Comment

by:show_t
ID: 9832355
Hello,

Basically, when i do this :

Select distinct Atozlisting -- alpha
from yourtable
where isnumeric(Atozlisting) = 0

IT WORKS! i get :
A
A
A
B
B
C
F
G
G
J
K
L
M
M

However,  i need the query to only return :
A
B
C
F
G
J
K
L
M

Do you see what i mean, without duplicates.

thanks
:-)
0
 
LVL 6

Accepted Solution

by:
lausz earned 125 total points
ID: 9833025
I don't understand ..

Try this two options :

Select distinct ltrim(Atozlisting) -- alpha
from yourtable
where isnumeric(Atozlisting) = 0

or


Select Atozlisting -- alpha
from yourtable
where isnumeric(Atozlisting) = 0
group by Atozlisting
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Backup Job question 4 20
SQL JOIN 6 39
Azure SQL DB? 3 21
Test a query 23 19
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now