CREATE FUNCTION [dbo].[tblfn_SplitIds]
(
@IdsString nvarchar(MAX)
)
RETURNS
@Idstable TABLE
(
items nvarchar(MAX)
)
AS
BEGIN
DECLARE @Delimiter char(1)
DECLARE @Idx int
DECLARE @Slice varchar(8000)
SET @Delimiter = ','
SELECT @Idx = 1
IF len(@IdsString)<1 OR @IdsString IS NULL RETURN
WHILE @idx!= 0
BEGIN
SET @idx = charindex(@Delimiter,@IdsString)
IF @idx!=0
SET @slice = LEFT(@IdsString,@idx - 1)
ELSE
SET @slice = @IdsString
IF(len(@slice)>0)
INSERT INTO @Idstable(Items) values(@slice)
SET @IdsString = RIGHT(@IdsString,len(@IdsString) - @idx)
IF len(@IdsString) = 0 BREAK
END
RETURN
RETURN
END
No comments:
Post a Comment