Populate string variable based on values in multi-value variable

I have a multi-value query variable names multiVar1 which get data from postgres/timescale DB.
Ex. Query: select name as __text and id as __value from testtable.
Lets say above query returns value as
name1 id1
name2 id2
name3 id3

I want to define another variable named stringVar1 which is formed by iterating over multiVar1
Ex.
foreach m in [[multiVar1]]: //stringVar1 should get populated with m

Finally stringVar1 should have values as ‘case when case=name1 then value end as name1, case when case=name2 then value end as name2, case when case=name3 then value end as name3’

Is there any way to achieved this in grafana?
OR
Is there any way we can repeat the query based on multi-value variable ex. multiVar1?

Need some suggestions on this?

Anyone any input on this?