Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Removing unwanted characters - Part 3

Apr 16 2012 1:03AM by Madhivanan   

In this series at Part 1 Removing unwanted characters , I posted a method that used a function. In part 2 I posted a method that used Dynamic SQL.

Here is another improved method that uses Dynamic SQL

--Create test data

create table #data (data varchar(100))

insert #data 
select 'tes^@&t %stri)-n!g' data union all
select '))aaer***********)' union all
select '&^&&hsdf()' union all
select 'jj&wk' union all
select ')hw*pa' union all
select 'No&@#$53*24,Mai()$n R--!oad'

--Create table that has all set of characters to be removed

create table clean_chars (char_id int identity(1,1),chars char(1))

insert into clean_chars (chars)
select '^' as repl union all 
select ')' union all
select '(' union all
select '&' union all
select '*' union all
select '%' union all
select '@' union all
select '-' union all
select ',' union all
select '#' union all
select '$' union all
select '#' union all
select '!' 

 declare @sql varchar(max), @select varchar(max)
 select @sql='',@select=''
 select @select=@select+'replace(', @sql=@sql+','''+chars+''','''')' from clean_chars

 select @select='select data,'+@select+'data'+@sql+' as cleaned_data from #data' 
 exec(@select)

The result is

data                                cleaned_data
--------------------------------------------------------
tes^@&t %stri)-n!g                  test string
))aaer***********)                  aaer
&^&&hsdf()                          hsdf
jj&wk                               jjwk
)hw*pa                              hwpa
No&@#$53*24,Mai()$n R--!oad         No5324Main Road


Tags: t-sql, sql_server, sqlserver, tsql, remove,


Madhivanan
3 · 39% · 12419
5
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • We can try like this also.

    declare @InputString VARCHAR(100)='))aaer***)' ,@col varchar(100)

    WHILE PATINDEX('%[^a-zA-Z0-9]%', @InputString) > 0 BEGIN SET @col = COALESCE(@col+' '+ SUBSTRING(@InputString,0,PATINDEX('%[^a-zA-Z0-9]%', @InputString)),SUBSTRING(@InputString,0,PATINDEX('%[^a-zA-Z0-9]%', @InputString))) SET @InputString = SUBSTRING(@InputString,PATINDEX('%[^a-zA-Z0-9]%', @InputString)+1,LEN(@InputString)-PATINDEX('%[^a-zA-Z0-9]%', @InputString)) END SET @InputString = COALESCE(@col + ' '+ @InputString,@InputString)

    select @InputString

    commented on Sep 25 2012 12:43AM
    mailtokvm
    355 · 0% · 115

Your Comment


Sign Up or Login to post a comment.

"Removing unwanted characters - Part 3" rated 5 out of 5 by 5 readers
Removing unwanted characters - Part 3 , 5.0 out of 5 based on 5 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]