2013-10-01 52 views
0

我有數據至少由特殊字符組成,但我的輸出不應顯示特殊字符或ascii字符。我只需要字母數字和空格,其他字符應該替換爲null。請提出一些方法來處理這我才知道PATINDEX將正常工作,但我不知道它是否會從一個字符串替換多個字符如何使用patindex從sybase中的字符串中刪除特殊字符

declare @a char 
select @a = 'tHo [email protected]' 

my output should be tHo masfi5com 

回答

0
DECLARE @str VARCHAR(400) 
    Declare @expres as varchar(50) = '%[~,@,#,$,%,&,*,(,),.,!]%' 
SET @str = 'tHo [email protected]' 
WHILE PATINDEX(@expres, @str) > 0 
      SET @str = Replace(REPLACE(@str, SUBSTRING(@str, PATINDEX(@expres, @str), 1),''),'-',' ') 
print @str 
+0

由於其工作正常,但我想做到這一點的檢查整個表格爲近30列。如果我使用這個條件每列我需要給30更新。是否有任何選項可以在整個表單上進行單擊 – Ramesh

+0

Hi Ramesh, 您可以像使用用戶功能一樣使用它並應用於特定列。 – Singh

相關問題