Overblog Follow this blog
Administration Create my blog
Balavardhan Reddy Narani

Query to remove the matching expression SQLServer

October 12 2012 , Written by Balavardhan Reddy Published on #SQL Server2005

A simple query to remove the particular patreen from the entire string, its just like reggular expression in the ASP.Net

Query to strip the matching expression charectors from string , 

Declare @myExpression varchar(50)

Declare @queryString varchar(max)

SET @myExpression =  '%['+@myExpression +']%'

    WHILE PatIndex(@myExpression, @queryString ) > 0

        SET @queryString = Stuff(@queryString , PatIndex(@myExpression, @queryString ), 1, '')

Select @queryString

Ex : 

set @queryString = '2fsfse54646vdf00_*gf,,dg45$'

set @myExpression = 'a-z*$,'

Result
25464600_45
Read more