I have here a stored procedure which expects two parameters
HeadID
integerKdNr
nvarchar(100)
The select in the stored procedure looks like this:
select *
from something
where HeadID = @HeadID and KdNr in (@KdNr)
Now I execute the stored procedure like this
exec spTest 21, ('64303')
This works but if I add multiple customer numbers (they are integers in the database)
exec spTest 21, ('64303', '64304', '64305')
I get an error:
Failed to convert nvarchar to integer.
Can someone please help me / tell me how do I pass multiple integers to a stored procedure like this?
1条答案
按热度按时间b4lqfgs41#
Use the below function in your procedure.
The above function will split the string into each row.
Now use the above function in your procedure like:
SELECT * FROM something WHERE HeadID = @HeadID AND KdNr IN (SELECT Data FROM dbo.SplitString(@KdNr, ',') WHERE Data <> '')
Now call your procedure like:
exec spTest 21, '64303,64304,64305'