SQLTeam.com | Weblogs | Forums

Hyperlink Column in SQL Table


#1

Hello,

Is it possible to create a hyperlink column in a SQL Server table? I was hoping to create a column which appears as Y but links through to a website like a normal hyperlink.

I created a test table as follows:

USE MIProcessing
CREATE TABLE Test
(Hyperlink nvarchar(255),
);

I then tried to use HTML code within an INSERT INTO statement to add the hyperlink.

INSERT INTO Test (Hyperlink)
VALUES ('Y')

However, this actually creates a text output as specified above.

Is there a way for the output in the table to appear as Y but with an active hyperlink that feeds through to a specified URL?

Thanks in advance


#2

There is a good discussion here:
https://social.msdn.microsoft.com/forums/sqlserver/en-US/86b046c9-e1a0-4d26-8ab9-25b99ebcbb35/giving-hyperlink-in-textnvarchar-column-of-sql-table


#3

It would be better to do this in your APP / Presentation layer.

However, if your table contains the columns "TextLink" and "HyperLink" you could do

SELECT '<a href="'
       + HyperLink
       + '">'
       + TextLink
       + '</a>'
FROM YourTable

which will give you something like

<a href="http://www.mysite.com/">Y</a>

The problem with it is that the Presentation layer will usually also be responsible for the CSS Style / Class, and all sorts of other "presentation" <Natch!> issues which you don't really want to have to adjust, and re-dploy, the SQL code when they need changing.

If you use HTML Templates in your code then you can probably write something like

Please click <a href="{HyperLink}">{TextLink}</a> to continue

and hook-up that Template to a

SELECT Hyperlink, Textlink from YourTable

to "merge" it with the actual database data