August 22, 2008 at 3:54 am
Hi,
I would like to pull back a results set with records that contain non-alphanumeric characters in a certain column. Is this possible using the ASCII codes?
Just thinking of a quicker way rather than using multiple LIKE statements.
Thanks!
Richard
August 22, 2008 at 4:03 am
Try PATINDEX Function.
August 22, 2008 at 4:04 am
Will this work?
select * from YourTable where YourColumn like '%[^a-zA-Z0-9]%'
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
August 22, 2008 at 4:15 am
RyanRandall (8/22/2008)
Will this work?
select * from YourTable where YourColumn like '%[^a-zA-Z0-9]%'
Thanks Ryan - That returns all alphanumeric values but I want the opposite. Tried the same as far as listing them within the square brackets but that didn't work.
Currently looking at the PATINDEX function.
August 22, 2008 at 4:25 am
richard (8/22/2008)
That returns all alphanumeric values but I want the opposite.
Huh? Did you see the not symbol (^)? Here's an example...
--Sample Data
declare @t table (v varchar(100))
insert @t
select 'H[1'
union all select 'y}1'
union all select 'a1'
union all select '1'
union all select 'g'
union all select ''
union all select null
--Query
select * from @t where v like '%[^a-zA-Z0-9]%'
/* Output
v
-----
H[1
y}1
*/
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
August 22, 2008 at 4:29 am
Sorry, my bad, did not see the ^ symbol.
Works great now - thanks!
August 22, 2008 at 4:30 am
No worries - glad to help 🙂
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
August 22, 2008 at 4:35 am
Another alternative may not be the best one
SELECT
YOURCOLUMN,
CASE WHEN PATINDEX('%[~,!,@,#,$,^,&,*,(,),_,+,=,-,|,\,:,;,",?,/,.,>,<,`]%',YOURCOLUMN) !=0
THEN 'Non - Alphanumeric'
ELSE 'Alphanumeric'
END AS FLAG
FROM YOURTABLE
Thanks,
Amit Khanna
January 6, 2010 at 11:29 am
How can I add apostrophe to this expression - char(39)?
For example, I should select all alpha-numeric name. However, some names contains apostrophe, like O'Brien.
select * from YourTable where YourColumn like '%[^a-zA-Z0-9'']%'
Did not work
January 6, 2010 at 11:41 am
I should select all alpha-numeric name
This makes it sound like you have a different requirement, since the original poster was asking for non-alphanumeric data. Maybe you want something like this?
--Sample Data
declare @t table (v varchar(100))
insert @t
select 'H[1'
union all select 'y}1'
union all select 'a1'
union all select '1'
union all select 'g'
union all select ''
union all select null
union all select 'smith'
union all select 'smith1'
union all select 'smith$'
union all select 'o''brien'
--Query
select * from @t where v not like '%[^a-zA-Z'']%'
/* Output
v
-----
g
smith
o'brien
*/
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
January 6, 2010 at 3:49 pm
Thanks Ryan
😀
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply