# Batch Insert Through a Procedure in Simple way

While I am working with the java team, they asked me  to insert a batch of queries through  procedure ; ie the input  is in the form of string as below,

(”va”,1,2),(”vb”,2,1)’

So splitting each column values  and inserting into the table is the first idea that came to my mind.After doing with string functions ,I become irritated.So I thought of execute a string .

CREATE PROC New_proc
AS
BEGIN

DECLARE @id VARCHAR(MAX)
DECLARE @str1 NVARCHAR(MAX)

SET @id = ( ‘(”va”,1,2),(”vb”,2,1)’ )
SET @str1 = (SELECT ‘insert into parents values’ + ‘ ’ + @id)

EXECUTE Sp_executesql @str1;
END