Is there any limit for IN results in SQL Server IN clause?

484    Asked by ankur_3579 in Salesforce , Asked on Jul 12, 2021

Is there any limit for the content that the IN filter can handle? For example:SELECT Name FROM People WHERE Job IN (All the values goes here) Microsoft docs for IN says: "Explicitly including an extremely large number of values (many thousands of values separated by commas) within the parentheses, in an IN clause can consume resources and return errors 8623 or 8632. To work around this problem, store the items in the IN list in a table, and use a SELECT subquery within an IN clause." but is there any exact or approximate number for many thousands of values

Answered by Anusha Acharya

It depends. Seriously. That’s why the docs can’t be specific about where you will notice degradation in your environment. The solution is to just stop doing this (and worrying about it) and use a table-valued parameter. If you have the values in C# in such a way that you can build a comma-separated list as a string to concatenate together in a query, you have the values in C# in such a way that you could stuff them in a DataTable or other structure (maybe that's where they're coming from in the first place), and pass that structure as a parameter to the stored procedure. What is SQL server IN clause? The SQL Server (Transact-SQL) IN condition is used to help reduce the need to use multiple OR conditions in a SELECT, INSERT, UPDATE, or DELETE statement.




Your Answer

Interviews

Parent Categories