Monday, July 31, 2017

▷ Mssql string cut (MSSQL 문자열 자르기)

[ Mssql string cut ]


-- SQL Query Document
-- Filename : STRCUT


-- Query Start

CREATE      FUNCTION STRCUT(@strTARGET VARCHAR(200), @DM char(01), @intCONTINUE int)
RETURNS VARCHAR(200)
AS
BEGIN
DECLARE @strSUBSTRING VARCHAR(200)
DECLARE @strRETURN VARCHAR(200)
DECLARE @strRTNVALUE VARCHAR(200)
DECLARE @intCOUNT int
SET @intCOUNT = 1
SET @strRETURN = @strTARGET

declare @len_strTARGET int, @dm_count int
set @dm_count=0
set @len_strTARGET=len(@strTARGET)

while (@intCOUNT <= @len_strTARGET)
begin
if (substring(@strTARGET,@intCOUNT,1)=@DM)
select @dm_count=@dm_count+1
select @intCOUNT=@intCOUNT+1

end

WHILE @intCONTINUE >= 1
BEGIN

if (@dm_count < @intCONTINUE-1)
begin
set @strRTNVALUE=''
break
end
else IF (CHARINDEX(@DM, @strRETURN)) > 0
BEGIN
SET @strRTNVALUE = SUBSTRING(@strRETURN, 1, CHARINDEX(@DM,@strRETURN)-1)
SET @strRETURN =  SUBSTRING(@strRETURN, CHARINDEX(@DM,@strRETURN)+1, LEN(@strRETURN))
END
ELSE
BEGIN
SET @strRTNVALUE = @strRETURN
BREAK
END

SET @intCONTINUE = @intCONTINUE -1
CONTINUE
END

RETURN(@strRTNVALUE)
END

-- Query End

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

No comments:

Post a Comment

◈ Recent Post

▷ UITest demo with TestOne (Mobile, Keypad and Drag until found tip)

[ UITest Demo Environment ] 1. UITest Solution: TestOne 2. Description 데모 설명    How to use keypad, and to drag until found.     키패드를...

◈ Popular Posts