Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlink a value in SQL Server query result in SSMS

I am trying to create something for our QA people, where a query that they would run will return a column with hyperlinked values. I am using SQL Server 2008 R2 and SSMS.

How will I hyperlink results in SSMS so a linked value opens in a browser?

The idea is that the Qa person can simply click on the link and the appropriate ASP.Net app would open in a browser window.

The query is as below, which is right now showing an unlinked string under DocLink column.

SELECT
 DocNumber,
'https://www.xyz.com/mypage.aspx?docNumber=' + CAST(DocNumber AS varchar(20)) AS   
     DocLink
FROM Docs
like image 741
Sunil Avatar asked Sep 16 '13 15:09

Sunil


People also ask

How do you create a hyperlink in SQL query?

You can do it using string concatenation. Note that this just return the url as a string; to show it as a hyperlink you have to add the appropriate html tags, but that should probably be done in the presentation layer of your application.

How do you give a value in SQL?

SQL Server provides us with two methods in T-SQL to assign a value to a previously created local SQL variable. The first method is the SET statement, the ANSI standard statement that is commonly used for variable value assignment. The second statement is the SELECT statement.


2 Answers

There is no way that I found to open URL directly from result pan but following is the way if you want to achieve open hyperlink from within SSMS.

Step 1. Cast the result to XML. i.e.

SELECT CAST('http://www.google.com' AS XML) Google 

Step 2. After executing the query, in the result window, click on the hyperlink. That will open another tab in SSMS.

enter image description here

enter image description here

Step 3. In this new tab, right click on the link and select Open URL option. This will open the link into the default browser.

enter image description here

Try that.

like image 181
ViKiNG Avatar answered Oct 20 '22 23:10

ViKiNG


Cast the result string as XML:

SELECT
CAST('https://www.xyz.com/mypage.aspx?docNumber=100' AS XML)
like image 28
ErikEJ Avatar answered Oct 20 '22 22:10

ErikEJ