TSQL - Make Excel Link In Output

ben himself's picture

Here is a situation I just came across (boiled down and simplified).  An end user was having to manually find a user id, navigate to an image folder, and then search through hundreds of images to find the one corresponding with that user.  Sure, they were in numerical order, but still, what a pain!  He wanted to generate an excel file with links to files to quickly access the corresponding image. 

So, I created a query that dynamically built the file path from data in the database, wrapped it in an Excel function, and then when the output is pasted into an Excel sheet, it links to the image.  Here is the TSQL code: