--去除特殊字符,只留0-9,a-z,A-Z
declare @teststr varchar(100)
set @teststr='test #123^we'
while patindex('%[^0-9a-zA-Z]%',@teststr)>0
SET @teststr=STUFF(@teststr, patindex('%[^0-9a-zA-Z]%',@teststr),1,'')
SELECT @teststr
----------------------------------------------------------------------------------------------------
test123we
(1 行受影响)