0

I'm wondering if it's doable to insert a clickable link into a table. I'm acutely aware that one can insert a link which will be clickable in SSMS but that's not what I want to accomplish. I'd like the link to be clickable in application. I've searched the Internet but I've only come across the articles about adding HTML tags to the INSERT statement which enables to open the link in SSMS.

create table #link (a varchar(max))


INSERT into #link  
VALUES ('<a href="http://www.google.com/">Y</a>'
)
Arkadiusz
  • 369
  • 5
  • 18
  • There is no such strict concept in relational databases. Clickable or any other way you present information, is handled by the presentation layer in your application. You can insert makeup like HTML in your database, which would present links as clickable once you display HTML in a HTML renderer. – TT. Oct 18 '19 at 07:36

1 Answers1

3

You can insert whatever you want into the database columns. But the action "Open this link on a click event!" is something your application has to do.

To put it even closer: The action "Take this string, paint just the text on the screen, let it look like a hyper link and navigate to the hidden URL on a click!" is something bound to a HTML engine. Pass HTML to any browser and the browser will do all this implicitly. But your database is just a container for data...

I would either use a column typed XML and treat the HTML as XHTML, or - this would be much! better - use two columns and create the link either within a query or - again better - in your application.

Assume a table like this:

DECLARE @TheLinkTable TABLE(ID INT IDENTITY,LinkText NVARCHAR(1000),LinkAddress NVARCHAR(1000));
INSERT INTO @TheLinkTable VALUES('Y','http://www.google.com/');

You can use a query like this

SELECT LinkAddress AS [a/@href]
      ,LinkText AS [a]
FROM @TheLinkTable
FOR XML PATH('');

And you might read into this answer, if you'd need a HTML-table actually.

But - as said above - I'd just read both values from separated columns and build the clickable link in the application.

Shnugo
  • 66,100
  • 9
  • 53
  • 114