column contains... / ? < > \ : * | "

/ ? < > \ : * | " 

I have a column [LabSampleNo] some with one of these characters. I want an update query

Update Table1 Set BadDataYN = true Where [LabSampleNo] contains (any of these characters)

Could this be done in Where clause?
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plusone3055Commented:
Update Table1 Set BadDataYN = true 
Where [LabSampleNo] LIKE '%[^a-zA-Z0-9]%'

Open in new window

PortletPaulEE Topic AdvisorCommented:
You can also "escape" characters, like this:
select
*
from table1
where astring like '%//%' escape '/'
or  astring like '%/?%' escape '/'
or  astring like '%/<%' escape '/'
or  astring like '%/>%' escape '/'
or  astring like '%/\%' escape '/'
or  astring like '%/:%' escape '/'
or  astring like '%/*%' escape '/'
or  astring like '%/|%' escape '/'
or  astring like '%/"%' escape '/'

Open in new window


CREATE TABLE Table1
	([astring] varchar(40))
;
	
INSERT INTO Table1
	([astring])
VALUES
	('1 / ? < > \ : * | "'),
	('2 /'),
	('3 ?'),
	('4 <'),
	('5 >'),
	('6 \'),
	('7 :'),
	('8 *'),
	('9 |'),
	('10 "')
;

Open in new window

|             ASTRING |
|---------------------|
| 1 / ? < > \ : * | " |
|                 2 / |
|                 3 ? |
|                 4 < |
|                 5 > |
|                 6 \ |
|                 7 : |
|                 8 * |
|                 9 | |
|                10 " |

Open in new window


see: http://sqlfiddle.com/#!3/e6dd7/1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Goodangel MatopeSoftware ArchitectCommented:
You can do it like so

UPDATE tableName
SET BadDataYN = 1 
WHERE LabSampleNo  LIKE N'%[^0-9A-Za-z .,;:]%'

Open in new window

Goodangel MatopeSoftware ArchitectCommented:
Oops, I see plusOne already had the same solution except for a few characters in the regular expression, so I guess he takes the cake on this one.... Had this page open too long while I was attending to other issues!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.