Assuming it's applicable with your queries, you're attempting to create the link at the wrong point.
It is possible to put the link building in your SELECT statement, itself:
SELECT '<a href="' + theLinkThing + '">Some Text</a>' AS MyLink, etc1, etc2, etc3
Note that 'Some Text' could also be from your query.
It's simply treated as another return value in SQL, in the above case, with an array index of [0] or ['MyLink']