在字符串0到9中,在SQL中用空格替换

时间:2014-06-21 08:47:34

标签: sql-server

我有String Like

208Pb,
75As,
111Cd

我想用空白和结果复发数字  AS赞

Pb,
AS,
cd 

1 个答案:

答案 0 :(得分:-1)

<强> Source

方法1:

  

尝试此功能:

Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

    Declare @KeepValues as varchar(50)
    Set @KeepValues = '%[^a-z]%'
    While PatIndex(@KeepValues, @Temp) > 0
        Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')

    Return @Temp
End
  

这样称呼:

Select dbo.RemoveNonAlphaCharacters('208Pb')

<强>输出:


Pb

方法2:

    DECLARE @str VARCHAR(400)
    DECLARE @expres  VARCHAR(50) = '%[0-9]%'
    SET @str = '208Pb'
    WHILE PATINDEX( @expres, @str ) > 0
      SET @str = Replace(REPLACE( @str, SUBSTRING( @str, PATINDEX( @expres, @str ), 1 ),''),'-',' ')

    SELECT @str

<强>输出:


Pb