If you are forced to do this in a stored procedure and your arrays are equal size you can join the two lists, split them, and then join on position (the number of elements in each array) to get the linked set you need.
The below example uses a number table, but you can replace that split operation with any.
-- if you dont have a number table:
/*
create table [dbo].[Number](n int not null primary key clustered);
insert into dbo.Number
values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
(11),(12),(13),(14),(15),(16),(17),(18),(19),(20)
*/
declare @lstid varchar(100) = '1,2,3,4,51',
@lstvalue varchar(100) = '10,20,22,35,60'
declare @Length tinyint,
@Input varchar(8000),
@Delimiter char(1)
-- sanity check
if len(@lstid)-len(replace(@lstid, ',', '')) <> len(@lstvalue)-len(replace(@lstvalue, ',', ''))
begin
raiserror('lists are not equal', 16, 1);
return;
end
--count the numbers of elements in one of the arrays
select @Length = len(@lstid)-len(replace(@lstid, ',', ''))+1;
--join the two arrays into one
select @Input = @lstid + ',' + @lstvalue;
set @Delimiter = ',';
;with cte (i,s)
as (
select row_number() over (order by n.n asc) [i],
substring(@Delimiter + @Input + @Delimiter, n.n + 1, charindex(@Delimiter, @Delimiter + @Input + @Delimiter, n.n + 1) - n.n - 1) [s]
from dbo.Number n
where n.n = charindex(@Delimiter, @Delimiter + @Input + @Delimiter, n.n) and
n.n <= len(@Delimiter + @Input)
)
select a.s, b.s
from cte a
join cte b on
a.i+@Length = b.i
order
by a.i;
return