Nathan
Nathan

Reputation: 1250

Procedure in SQL that accepts dynamic array of inputs

Does SQL Server have the ability to accept a dynamic array of inputs and loop through the values?

For example:

I have multiple products with productId. Now, there will be times that I would need to delete some of those products. I can do this now by executing a stored procedure that accepts a productId value. My problem is I need to do this one by one.

What I would like to do is to send multiple productId's to the procedure and have the proc loop through those id's.

Is this possible?

Upvotes: 1

Views: 87

Answers (1)

Dimt
Dimt

Reputation: 2328

This is possible in SQL Server 2008 using Table-Valued Parameters, in SQL Server 2005 is work around it by passing a Comma-separated List of Values. You can see all available options and implementations for 2008 here and for 2005 here.

Upvotes: 2

Related Questions