I need to write a T-SQL query with something like:
WHERE
tbl.field IN (%a lot of variants%)
But I can't because of limitation of 2100 items for parameters count in SQL Server.
How can I find the way around this problem?
I need to write a T-SQL query with something like:
WHERE
tbl.field IN (%a lot of variants%)
But I can't because of limitation of 2100 items for parameters count in SQL Server.
How can I find the way around this problem?
One easy way is to use OPENJSON, and pass the list not as individual parameters, but as a single NVARCHAR(MAX) parameter that's parsed on the server. EG
select *
from large
where id in (select cast(value as int) from openjson(@values))
Where @values is a parameter of type NVARCHAR(MAX) containint a JSON Array of scalars. Like
var values = "[1,2,3,4,5,6,7,8]";
And as a bonus it performs much better too.
You need to you a subquery!
SELECT VAR1, VAR2
FROM TABLE
WHERE
(SELECT.. FROM.. ETC)