Hi:
Sorry for intercepting in this thread, I once ran into such a solution.
I believe our friend SomeNewTricks2, is trying to send a block of data to the SP.
I had once to do so, so that I don't do multiple inserts for the same UserID, so I concated the user records and sent them as one block.
I do vote for Terri's second approach, and if you are interested in having such a function you can try the following:
CREATE FUNCTION dbo.fn_SplitAt
(
@List NVARCHAR(2000),
@SplitOn NVARCHAR(5),
@Position INT
)
RETURNS VARCHAR(100)
AS
BEGIN
DECLARE @IPosition INT
DECLARE @RtnValue VARCHAR(100)
SET @IPosition = 1
-- While a delimiter is found in the original list
WHILE ( CHARINDEX(@SplitOn,@List) > 0 )
BEGIN
-- If the position of the required item equals to the counter of the current item
IF ( @IPosition = @Position )
BEGIN
-- Get that data
SET @RtnValue = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1)))
END
-- Incrememt the cursor
SET @IPosition = @IPosition + 1
-- Remove from the original list the already checked item
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
END
-- We might be asking the last item in the original string
IF ( @RtnValue IS NULL )
SET @RtnValue = @List
RETURN (@RtnValue)
END
The above function I once used it from the 4GuysFromRolla.com website, originally, it only splits a string based on a delimiter, but what I did is I made it return only a specific item in the given string based on the position specified, which is an input too.
Hope it helps,
Thank you Terri for such a great solution, they make one have a wide understanding of what one can do in SQL Server.
Regards