Create FUNCTION List_to_vc_table
(@list varchar(8000))
RETURNS @tbl Table (number varchar(1000) not null)
AS
--Returns The Given Comma Specified list in Varchar Table
BEGIN
DECLARE @ID varchar(20), @Pos int
SET @list = LTRIM (RTRIM (@list) )+ ','
SET @Pos = CHARINDEX(',' , @list, 1)
IF REPLACE (@list, ',', ' ') <> ''
BEGIN
WHILE @Pos >0
BEGIN
SET @ID = LTRIM(RTRIM(LEFT(@list, @Pos - 1)))
IF @ID <> ' '
BEGIN
INSERT @tbl (number) values (@ID)
END
SET @list = RIGHT(@list, LEN (@list) - @Pos)
SET @Pos = CHARINDEX(',' , @list, 1)
END
END
return
END
No comments:
Post a Comment