Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 speacial char query

Author  Topic 

nextaxtion
Yak Posting Veteran

54 Posts

Posted - 2014-02-07 : 02:08:35
hi team ,

i need to find and all speacial charcheters and replace with space.
Following query works well for me to finding all rows having speacial char.


SELECT DESC FROM TBL_DESC
WHERE DESC LIKE '%[^A-Z0-9 ]%'


Kindly help me in replacing speacial char with space . i need to remove speacil chars only.

prithvi nath pandey

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-02-08 : 06:04:33
Try this:
with cte
as (select [DESC] as org_desc
,cast(left([DESC],patindex('%[^A-Z0-9 ]%',[DESC])-1)
+right([DESC],len([DESC])-patindex('%[^A-Z0-9 ]%',[DESC]))
as varchar(40)
) as new_desc
from TBL_DESC
where [DESC] like '%[^A-Z0-9 ]%'
union all
select org_desc
,cast(left(new_desc,patindex('%[^A-Z0-9 ]%',new_desc)-1)
+right(new_desc,len(new_desc)-patindex('%[^A-Z0-9 ]%',new_desc))
as varchar(40)
) as new_desc
from cte
where new_desc like '%[^A-Z0-9 ]%'
)
select *
from cte
where new_desc not like '%[^A-Z0-9 ]%'
You probably want to change the type and length og the fields marked in red.
Go to Top of Page

zenajaero
Starting Member

2 Posts

Posted - 2014-02-08 : 09:49:01
where on my keyboard are the signs between the two plus on the following query.
SELECT FirstName + ' ' + LastName AS FullName
FROM YourTable.

za
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-10 : 08:33:52
quote:
Originally posted by zenajaero

where on my keyboard are the signs between the two plus on the following query.
SELECT FirstName + ' ' + LastName AS FullName
FROM YourTable.

za


whats your keyboard type. Default keyboard has it coming just to left of enter key.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -