Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 want to check if column has alphanumeric chars

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 link

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=113653
Go to Top of Page

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 yourColumn
end
from yourTable


Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

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 yourColumn
end
from 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.
Go to Top of Page

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.
Go to Top of Page

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.
Go to Top of Page

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 t
where data like '%[a-z]%' and data like '%[0-9]%'
[/code]

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 t
where data like '%[a-z]%' and data like '%[0-9]%'


Madhivanan

Failing to plan is Planning to fail


Madhi wont this return special string containing characters as well?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-07 : 02:02:24

Yes

Here is modified code

select 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 t
where data like '%[a-z]%' and data like '%[0-9]%'



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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]%'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-07 : 02:17:10
Cool... this looks fine...
Go to Top of Page
   

- Advertisement -