Author |
Topic |
SQLIsTheDevil
Posting Yak Master
177 Posts |
Posted - 2008-11-03 : 11:41:58
|
I have a varchar column which contains a select number of alphanumeric cells. In a select statement -- not a function or proc -- i want to check if said column contains any alphanumeric characters. I can check it against a specific character set using a combination of isnull and nullif. But is there a way I can, say, use nullif to check if the column contains alphanumeric cells. May I employ regular expressions? Any ideas? Thank you in advance. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 11:53:43
|
use function given in below linkhttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113653 |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-11-03 : 12:07:33
|
Do you mean like this?select case when yourColumn like '%[^0-9]%' then null else yourColumnendfrom yourTable Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-03 : 12:13:09
|
quote: Originally posted by webfred Do you mean like this?select case when yourColumn like '%[^0-9]%' then null else yourColumnendfrom yourTable Webfred No, you're never too old to Yak'n'Roll if you're too young to die.
this will check only it does not contain numerals. you need to check presence of both alphabets and numerals for it to be alphanumeric. |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-11-03 : 15:07:39
|
Oh sorry. I have completely misunderstood.Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
SQLIsTheDevil
Posting Yak Master
177 Posts |
Posted - 2008-11-06 : 16:53:47
|
Thank you very much to all for your help. I got it to work. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-07 : 00:56:15
|
[code]select data from( select '23498' as data union all select 'tetst' union all select 'kj98' union all select 'ad912') as twhere data like '%[a-z]%' and data like '%[0-9]%' [/code]MadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 01:51:17
|
quote: Originally posted by madhivanan
select data from( select '23498' as data union all select 'tetst' union all select 'kj98' union all select 'ad912') as twhere data like '%[a-z]%' and data like '%[0-9]%' MadhivananFailing to plan is Planning to fail
Madhi wont this return special string containing characters as well? |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-07 : 02:02:24
|
YesHere is modified codeselect data from( select data from ( select '23498' as data union all select 'tetst' union all select 'kj&98' union all select 'ad912' ) as t where (data not like '%[^0-9a-z]%') ) as twhere data like '%[a-z]%' and data like '%[0-9]%' MadhivananFailing to plan is Planning to fail |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-07 : 02:07:04
|
No need of two derived tables select data from ( select '23498' as data union all select 'tetst' union all select 'kj&98' union all select 'ad912' ) as t where (data not like '%[^0-9a-z]%') and data like '%[a-z]%' and data like '%[0-9]%' MadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 02:17:10
|
Cool... this looks fine... |
 |
|
|