Sample query I'm not sure would work or not :
Declare @UserInputForeignSource varchar(50)
Set @UserInputForeignSource = 'Customer'
SELECT * FROM AssociateTable t1
LEFT JOIN Customer t2 ON t1.ForeignId = t2.id AND @UserInputForeignSource = t1.ForeignSource
LEFT JOIN Vendor t3 ON t1.ForeignId = t3.id AND @UserInputForeignSource = t1.ForeignSource