I have table for example temp
Id Col1 Col2 Col3
1 1 2 3
and I have another table joininfo
Id SourceKey Table TargetKey
1 Col1 A ColA
2 Col2 B ColB
3 Col3 C ColC
I want to generate a query which will add inner join clause dynamically and will look like this
SELECT * FROM temp
INNER JOIN A ON Col1=ColA
INNER JOIN B ON Col2=ColB
INNER JOIN C ON Col3=ColC
Any help?