SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Special characters in a string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bpuccha
Starting Member

34 Posts

Posted - 09/13/2012 :  15:35:53  Show Profile  Reply with Quote
Hi,

How to check only the below special characters in a string

"\", "/", ":", "?", CHR(34), "*", "<", ">", "|", "'", "." and ","

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/13/2012 :  15:44:29  Show Profile  Reply with Quote
If you are interested just in detecting the existence of those special characters, you can do something like this - I have inserted only a few of the characters in your list in the like clause, you will need to insert them all.
DECLARE @string VARCHAR(32) = 'abcdr:x';
SELECT CASE 
            WHEN @string LIKE '%[\/:?]%' THEN 'Special chars exist'
            ELSE 'No special chars found'
       END
If you need more information, what are the kinds of information you need?
Go to Top of Page

bpuccha
Starting Member

34 Posts

Posted - 09/13/2012 :  15:50:35  Show Profile  Reply with Quote
I just want to detect whether it has any of those special characters or not, I tried that but it not allowing "'" and CHAR(34)(").

How to include those to into the list?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 09/13/2012 :  16:17:07  Show Profile  Reply with Quote
quote:
Originally posted by bpuccha

I just want to detect whether it has any of those special characters or not, I tried that but it not allowing "'" and CHAR(34)(").

How to include those to into the list?


for quotes you need to escape it while using

so use
'''' for including a ' in a string

see

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bpuccha
Starting Member

34 Posts

Posted - 09/13/2012 :  16:28:00  Show Profile  Reply with Quote
tried below code..It worked fine..Thanks

if replace(substring('@tmpvariable',1,10),' ' ,'') like '%[\/:?*<>|.,''''"]%'
begin
print 'it has special chars'
end
else
begin
print 'it doesnt have special chars'
end
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 09/13/2012 :  16:48:11  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000