I get the error \"Conversion failed when converting the nvarchar value \'23,24,3,45,91,\' to data type int.\" The error seems to be occuring on the ON clause. E.ID is an int
Using xml datatype, you can explode your string to integers like this. Good candidate for a user defined function I would say :-)
declare @test varchar(max)
set @test = '1,2,3,4,5'
select
T2.item.value('(./text())[1]','int')
from
(select convert(xml,''+replace(@test,',',' ')+' ') as xmldoc)
as xmltable
CROSS APPLY xmltable.xmldoc.nodes('/items/t') as T2(item)