dbTalk Databases Forums  

how to identify special characters with a single case statement

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss how to identify special characters with a single case statement in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rshivaraman@gmail.com
 
Posts: n/a

Default how to identify special characters with a single case statement - 05-08-2007 , 01:10 PM






hi All :

I have an insert statement which reads

INSERT Into TableA (Col1)

SELECT CASE WHEN Col1 LIKE '%[a-z]%' THEN 999999 ELSE Col1 END AS
Col1,
FROM TableB

**********************
TableA. Col1 has a datatype of Int.
TableB. Col1 has a datatype of varchar.

My insert is failing as it is trying to insert special character,
identifying a \ in the input column

How can i write a similar case statement to filter out special
characters and replace with 99999

Also can you refer me to a place where i can have a list of special
characters and if need be write mulitple case statements to filter
them out.

thanks
RS


Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: how to identify special characters with a single case statement - 05-08-2007 , 02:07 PM






You can negate your logic here and instead of looking to catch all invalid
characters, look for all characters excluding the set of digit characters.
It will be something like this:

INSERT INTO TableA
(Col1)
SELECT
CASE WHEN Col1 LIKE '%[^0-9]%'
THEN 999999
ELSE Col1 END
FROM TableB;


HTH,

Plamen Ratchev
http://www.SQLStudio.com



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.