ALTER FUNCTION [dbo].[udf_GEN_
(
@DelimiterFirst VARCHAR(5),
@DelimiterSecond VARCHAR(5),
@List NVARCHAR(MAX)
)
RETURNS @TableOfValues table
( RowID smallint IDENTITY(1,1),
[Value] varchar(50)
)
AS
BEGIN
----select * from [udf_GEN_
DECLARE @LenString int
WHILE len( @List ) > 0
BEGIN
SELECT @LenString =
(CASE charindex( @DelimiterFirst, @List )
WHEN 0 THEN len( @List )
ELSE ( charindex( @DelimiterFirst, @List ) -1 )
END
)
IF SUBSTRING( @List, 1, @LenString ) <> ''
BEGIN
--INSERT INTO @TableOfValues SELECT substring( @List, 1, @LenString )
--print(substring( @List, 1, @LenString ))
-------------
declare @SecondList varchar(8000)
DECLARE @LenStringSecond int
set @SecondList =substring( @List, 1, @LenString )
WHILE len( @SecondList ) > 0
BEGIN
SELECT @LenStringSecond =
(CASE charindex( @DelimiterSecond, @SecondList )
WHEN 0 THEN len( @SecondList )
ELSE ( charindex( @DelimiterSecond, @SecondList ) -1 )
END
)
IF SUBSTRING( @SecondList, 1, @LenStringSecond ) <> ''
BEGIN
INSERT INTO @TableOfValues SELECT substring( @SecondList, 1, @LenStringSecond )
--print(substring( @SecondList, 1, @LenStringSecond ))
END
SELECT @SecondList =
(CASE ( len( @SecondList ) - @LenStringSecond )
WHEN 0 THEN ''
ELSE right( @SecondList, len( @SecondList ) - @LenStringSecond - 1 )
END
)
END
---------
END
SELECT @List =
(CASE ( len( @List ) - @LenString )
WHEN 0 THEN ''
ELSE right( @List, len( @List ) - @LenString - 1 )
END
)
END
RETURN
END
No comments:
Post a Comment