Saturday, June 22, 2013

Get Alphabates From Alphanumeric String

create function dbo.getAlphabatesFromAlphanumeric
(
@alphanumeric varchar(8000)
)
returns varchar(8000)
as
begin
declare @replacementPossition int
set @replacementPossition=(select patindex('%[0-9]%',@alphanumeric))
while (@replacementPossition>0)
begin
set @alphanumeric=(select stuff(@alphanumeric,@replacementPossition,1,''))
set @replacementPossition=(select patindex('%[0-9]%',@alphanumeric))
end
return @alphanumeric
end

-- select dbo.getAlphabatesFromAlphanumeric('123ABC345')

No comments:

Post a Comment