본문 바로가기
MS-SQL/Function

ASCII 함수를 이용한 숫자만 추출해보는 간단한 함수 예제

by Hwoarang757 2013. 2. 1.

CREATE FUNCTION dbo.UDF_RETURN_NUMBER

(

@IN_PARAM_TEXT NVARCHAR(4000)

)

RETURNS NVARCHAR(512)

 

AS

BEGIN

 

             DECLARE @RETURNVALUE nvarchar(512)

            

             DECLARE @TEXTLENGTH INT

             SET @TEXTLENGTH = LEN(@IN_PARAM_TEXT);

            

             DECLARE @ADDLENGTH INT

             SET @ADDLENGTH = 1

            

             WHILE @TEXTLENGTH >= @ADDLENGTH

                           BEGIN

                                       

                                        IF ((ASCII(SUBSTRING(@IN_PARAM_TEXT,@ADDLENGTH,1)) >= 48) and (ASCII(SUBSTRING(@IN_PARAM_TEXT,@ADDLENGTH,1)) <= 57))

                                        BEGIN

                                                                  SET @RETURNVALUE = ISNULL(@RETURNVALUE,'') + SUBSTRING(@IN_PARAM_TEXT,@ADDLENGTH,1)

                                        END

                                       

                                        SET @ADDLENGTH = @ADDLENGTH  +1

                                       

                           END

            

             RETURN @RETURNVALUE

            

            

END

 

-_-;;;

항상 느끼는거지만 내가 뭔가 작성할때마다 뭔가 부족하다 -_-;; ㅠㅠ