My favourite technique up to some years ago was to have an arsenal of splitting functions, that could split a delimited list of homogeneous values (e.g. all integers, all booleans, all datetimes, etc.) into a table variable. Here is an example of such a function.
CREATE FUNCTION [dbo].[fn_SplitInt](@text varchar(8000),
@delimiter varchar(20) = '|')
RETURNS @Values TABLE
(
pos int IDENTITY PRIMARY KEY,
val INT
)
AS
BEGIN
DECLARE @index int
SET @index = -1
-- while the list is not over...
WHILE (LEN(@text) > 0)
BEGIN
-- search the next delimiter
SET @index = CHARINDEX(@delimiter , @text)
IF (@index = 0) -- if no more delimiters (hence this field is the last one)
BEGIN
IF (LEN(@text) > 0) -- and if this last field is not empty
INSERT INTO @Values VALUES (CAST (@text AS INT)) -- then insert it
ELSE -- otherwise, if this last field is empty
INSERT INTO @Values VALUES (NULL) -- then insert NULL
BREAK -- in both cases exit, since it was the last field
END
ELSE -- otherwise, if there is another delimiter
BEGIN
IF @index>1 -- and this field is not empty
INSERT INTO @Values VALUES (CAST(LEFT(@text, @index - 1) AS INT)) -- then insert it
ELSE -- otherwise, if this last field is empty
INSERT INTO @Values VALUES (NULL) -- then insert NULL
SET @text = RIGHT(@text, (LEN(@text) - @index)) -- in both cases move forward the read pointer,
-- since the list was not over
END
END
RETURN
END
When you have a set of functions like these, then your problem has a solution as simple as this one:
CREATE PROCEDURE sp_insert_information
(
@profileID as varchar(2000),
@profileName as varchar(8)
@profileDescription as varchar(100)
)
AS
BEGIN
DECLARE @T TABLE (Id int)
INSERT INTO @T (Id)
SELECT val FROM dbo.fn_SplitInt(@profileID)
INSERT INTO information(profileid, profilename,profiledescription)
SELECT Id, @profileName, @profileDescription
FROM @T
END
But today it might be quicker to execute, and even require less coding, to generate an XML representation of the data to insert, then pass the XML to the stored procedure and have it INSERT INTO table SELECT FROM xml, if you know what I mean.