-1

I have the following code

declare @code nvarchar
set @code='2/2017,3/2017'

select *
from payroll
where id_code in (@code)

But I am getting an error in the where clause.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

3

If you are using SQL Server 2016 you can use STRING_SPLIT

declare @code nvarchar
set @code='2/2017,3/2017'

select *
from payroll
where id_code in (SELECT value FROM STRING_SPLIT(@code,','))

for older versions of SQL you can use this as a guide T-SQL split string based on delimiter

Victor Hugo Terceros
  • 2,969
  • 3
  • 18
  • 31