I have a stored procedure which accept a parameter of type VARCHAR(MAX)
. That parameter has string separated by commas like
@test = 'test123,test456,test789';
Based on that parameter, I want to generate multiple insert statements.
I'll use the split function defined in this question: Split string by comma in SQL Server 2008.
Can you show me an example how to generate inserts after splitting a string by commas ?
The logic steps should be like:
@test = 'test123,test456,test789';
split @test
use while or cursor ? (I don't know)
INSERT INTO X values ('test123')
INSERT INTO X values ('test456')
...