-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
  • 704,970
  • 168
  • 1,303
  • 1,425

1 Answers1

2

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,750
  • 2
  • 17
  • 31