For example:
declare @values varchar(max) = '100,250,30,700'
select *
from MyTable
where id in (select [value] from string_split(@values, ','))
-- OR:
select t.*
from MyTable t
inner join string_split(@values, ',') as v on v.value = t.id
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Is it possible to declare a variable with multiple items like an in for a where clause?
For example:
declare @values varchar(max) = '100,250,30,700'
select *
from MyTable
where id in (select [value] from string_split(@values, ','))
-- OR:
select t.*
from MyTable t
inner join string_split(@values, ',') as v on v.value = t.id