문자열에서 특수문자 제거
-- 0-9, a-z and A-Z 제외한 모든 문자 제거
create function dbo.RemoveSpecialChars (@s varchar(256)) returns varchar(256)
with schemabinding
begin
if @s is null
return null
declare @s2 varchar(256)
set @s2 = ''
declare @l int
set @l = len(@s)
declare @p int
set @p = 1
while @p <= @l begin
declare @c int
set @c = ascii(substring(@s, @p, 1))
if @c between 48 and 57 or @c between 65 and 90 or @c between 97 and 122
set @s2 = @s2 + char(@c)
set @p = @p + 1
end
if len(@s2) = 0
return null
return @s2
end
-- 사용방법
select dbo.RemoveSpecialChars('abc-123+ABC')
결과: abc123ABC
'DataBase > MSSQL' 카테고리의 다른 글
작업스케줄한눈에보기 (0) | 2023.10.05 |
---|---|
특정단어가 포함되어 있는 트리거 찾기 (0) | 2023.10.05 |
프로시저 실행 결과를 txt 파일로 저장하기 (0) | 2023.10.05 |
프로시져수정및생성일자확인 (0) | 2023.10.05 |
프로시져해당문구찾기 (1) | 2023.10.05 |