우편번호나 전화번호등의 숫자들만 필요한 데이터에서 숫자만 남겨두고 제거 하는 방법이다.
Sqler.com 을 보다가 함수로 만들어 놓은게 있어서 테스트 할겸 해서 펼쳐 봤다.
DECLARE @InString VARCHAR(20)
DECLARE @cleanString VARCHAR(20)
SET @InString = '151*5-5!5'
--initialize String to not null
SET @cleanString = ''
--create a variable to use in looping thru string
DECLARE @position INT
SET @position = 1
--get length of input string
DECLARE @strLength INT
SET @strLength = LEN(@InString)
--start looping
WHILE @position <= @strLength
BEGIN
--get ascii table number and find out if is a number
IF ASCII(SUBSTRING(@InString, @position, 1)) BETWEEN 48 AND 57
BEGIN
SET @cleanString = @cleanString + SUBSTRING(@InString, @position, 1)
END
--increment to next character
SET @position = @position + 1
END
PRINT @cleanString
*출처 : http://www.sqler.com/index.php?mid=bColumn&page=77&document_srl=104531
'프로그램 경험 > Database' 카테고리의 다른 글
[SqlServer] PIVOT 기능 사용하기(행열 변환) (0) | 2014.09.15 |
---|---|
[SqlServer] 실행 프로시저 찾기 (0) | 2014.08.06 |
[SqlServer] SQL Server 2008 암호 저장 기능 안되는 미친 버그 (0) | 2014.07.08 |
[SqlServer] 데이터베이스 서버 IP 주소 알아내기 (0) | 2013.11.04 |
[SqlServer] 키워드 'with' 근처의 구문이 잘못되었습니다. 이 문이 공통 테이블 식이거나, xmlnamespaces 절이거나, 변경 내용 추적 컨텍스트 절인 경우에는 이전 문을 세미콜론으로 종료해야 합니다. (0) | 2013.09.04 |