[ Mssql string cut ]
-- 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