Skip to content
Advertisement

Passing string of parameters to stored procedure

I have a stored procedure that needs to accept a parameter @pnumber as a string of values like 1001,1002,1003...

My stored procedure looks like this:

My data:

The problem with this stored procedure is – when I input the parameter as (1001,1002) the query produced looks like this:

My query should actually look as below:

Rextester link : https://rextester.com/USZRB48933

Is there a way to fix this?

Advertisement

Answer

No need for the Dynamic SQL

If 2016+, you can use string_split()

Example dbFiddle

Returns

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement