Madhivanan's TSQL Blog

Find Alphanumerals only

Sometimes when you import data from other system, you may need to clean the data by removing unwanted data.
Consider you import data where you want to keep only those which are purely alphanumerals. Here is a way to find out

declare @table table(data varchar(20))
Insert into @table
select '23498' as data union all
select 'tetst' union all
select 'kj&98' union all
select 'ad912'
select data from @table
where (data not like '%[^0-9a-z]%') and data like '%[a-z]%' and data like '%[0-9]%'