well I hate to do such a things on SQL Server, but
declare @FieldName nvarchar(max) = '[a],[b],[c],[d]'
declare @values nvarchar(max) = '5,6,7,8'
declare @i int, @j int, @break int
declare @a nvarchar(max), @b nvarchar(max), @result nvarchar(max)
select @break = 0
while @break = 0
begin
select @i = charindex(',', @FieldName), @j = charindex(',', @values)
if @i > 0 and @j > 0
begin
select @a = left(@FieldName, @i - 1), @b = left(@values, @j - 1)
select @FieldName = right(@FieldName, len(@FieldName) - @i), @values = right(@values, len(@values) - @j)
end
else
begin
select @a = @FieldName, @b = @values, @break = 1
end
if @a in ('[b]', '[d]')
select @result = isnull(@result + ' & ', '') + @a + '=' + @b
end
select @result
You can also put all this list into temporary/variable table and do join.
select *
from
(
select T.<yourcolumn>, row_number() over (order by T.<yourcolumn>) as rownum
from <temptable1> as T
) as F
inner join
(
select T.<yourcolumn>, row_number() over (order by T.<yourcolumn>) as rownum
from <temptable2> as T
) as V on V.rownum = F.rownum
Or, even better, you can pass parameters into sp in xml form and not in distinct lists