pensavo che @listaid contenesse un solo parametro.
invece che passare la stringa nel formato "'1', '2', '3'" passala nel formato "1, 2, 3"
poi
codice:
create procedure xyz @listaId varchar(2000) = NULL AS
declare @wherestr varchar(8000)
declare @start int
declare @indx int
declare @working int
set @start = 1
set @working = 1
set @wherestr = ''
if @listaid is null
return
while @working = 1
begin
set @indx = charindex(',', @listaid, @start)
if @indx = 0
begin
set @working = 0
set @wherestr = @wherestr + ' or [ID] = ' + substring(@listaid, @start,len(@listaid) - @start + 1)
end
else
set @wherestr = @wherestr + ' or [ID] = ' + substring(@listaid, @start, @indx - @start )
set @start = @indx + 1
end
if len(@wherestr) > 0
begin
set @wherestr = ' WHERE ' + substring(@wherestr, 5, len(@wherestr) - 4)
execute ('SELECT * FROM TABELLA ' + @wherestr)
end