Hi I ant to create a function that returns a temp table. What I want to do is pass a string into a funtion then this function returns a table.
My string will be '215,216,303,782'
The table it returns will be
ID
215
216
303
782
My function will have the main code like
CREATE TABLE #ClientRef (Client int)
DECLARE @OldPos AS int
DECLARE @NewPos AS int
DECLARE @Counter As Int
SET @Counter = 1
SET @Client_Ref = ',' + @Client_Ref + ','
WHILE @Counter + 1 < len(@Client_Ref)
BEGIN
SET @OldPos = CHARINDEX( ',', @Client_Ref, @Counter)
SET @NewPos = CHARINDEX( ',', @Client_Ref, @OldPos + 1)
INSERT INTO #ClientRef (Client)
SELECT SUBSTRING ( @Client_Ref , @OldPos + 1, @NewPos - (@OldPos + 1))
SET @Counter = @NewPos - 1
END
However, this will not work.
Any ideas???
My string will be '215,216,303,782'
The table it returns will be
ID
215
216
303
782
My function will have the main code like
CREATE TABLE #ClientRef (Client int)
DECLARE @OldPos AS int
DECLARE @NewPos AS int
DECLARE @Counter As Int
SET @Counter = 1
SET @Client_Ref = ',' + @Client_Ref + ','
WHILE @Counter + 1 < len(@Client_Ref)
BEGIN
SET @OldPos = CHARINDEX( ',', @Client_Ref, @Counter)
SET @NewPos = CHARINDEX( ',', @Client_Ref, @OldPos + 1)
INSERT INTO #ClientRef (Client)
SELECT SUBSTRING ( @Client_Ref , @OldPos + 1, @NewPos - (@OldPos + 1))
SET @Counter = @NewPos - 1
END
However, this will not work.
Any ideas???