views:

56

answers:

3
+3  Q: 

SQL Max parameters

I read here that the maximum number of parameters that can be passed to a Stored Procedure is 2100.

I am just curious what kind of system would require a SP with 2100 parameters to be passed, and couldn't one split that into multiple SPs?

I thought that maybe an SP that calls multiple SPs would require a lot of params to be passed, I just can't fathom writing out that disgusting EXEC statment.

+1  A: 

I had a situation where I had to run something quite like the following:

SELECT 
  ...
WHERE
  ID IN (?,?,?,?...)

The list of parameters featured all entities the user had permission to use in the system (it was dinamically generated by some underlying framework). Turns out that the SGBD had a limitation on the number of parameters to be passed like this, and it was below 2100 (IIRC, it was Oracle and the maximum were 999 parameters in the IN list).

This would be a nice example of a rather long list of parameters to something that had to be a stored procedure (we had more than 999 and less than 2100 parameters to pass).

Don't know if the 999 constraint apply to sql server, but it is definately a situation where the long list would be useful...

Rodrigo Gama
I have come across that limit in Oracle of 1000 parameters per IN expression more than once. Funnyly you could work around it by using more than one IN condition: `id IN (first 1000 ids) OR id IN (next 1000 ids)`.
Jörn Horstmann
Yes. This was a long time ago but IIRC, that's what we did at the time.
Rodrigo Gama
it would be easier to pass in a CSV list of parameters and split them into rows within the stored procedure where you can join to them or otherwise use them as a table.
KM
+3  A: 

If you have a stored procedure using 2100 parameters you most likely have some sort of design problem.

Passing in a CSV list of values in a single parameter (and using a table value split function to turn those into rows), or using a table value parameter would be much easier than handling all of those input parameters.

KM
+1: This is one of those "if you have to ask.." questions
OMG Ponies
That was my first thoughts when I read this fact.
Jim
+2  A: 

The limit of procedures parameters predates both the XML data type and the table valued parameters, so back in those days there was simply no alternative. Having 2100 parameters on a procedure does not necessarily mean a human wrote it nor that a human will call it. It is quite common in generated code, like code created by tools and frameworks, to push such boundaries for any language, since the maintenance and refactoring of the generated code occur in the generating tool, not in the result code.

Remus Rusanu