Click here to Skip to main content
14,743,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Let's say i have this procedure

CreatePROCEDURE [dbo].[usp_InsertValue]
	 @value nvarchar(5)
         ,@value1 int

and i have already a variable that has values separated by comma called @value

What I have tried:

exec usp_InsertValue  value from STRING_SPLIT(@value, ','),@value1

but i'm getting incorrect syntax near from
Updated 6-Jul-20 22:06pm

1 solution

Basically, don't use comma delimited data anywhere near SQL - it's always going to be a PITA at some point even though it is possible. For example: Using comma separated value parameter strings in SQL IN clauses[^] and Converting comma separated data in a column to rows for selection[^]
If nothing else, you may introduce an SQL Injection vulnerability which could compromise of destroy your DB.

And that syntax you show makes no sense at all - which is why SQL is rejecting it.
I assume you are trying to execute the SP once for each string in your CSV data - if so, you will need a loop with the SP EXEC inside it - but I'd strongly suggest you find a different way to achieve whatever it is that makes you think this is a good idea!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900