{"id":438,"date":"2023-07-28T19:53:25","date_gmt":"2023-07-28T19:53:25","guid":{"rendered":"https:\/\/grionic.com\/?p=438"},"modified":"2023-07-29T19:54:20","modified_gmt":"2023-07-29T19:54:20","slug":"hyperlinks-in-sql-server","status":"publish","type":"post","link":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/","title":{"rendered":"Hyperlinks in SQL Server – Insert, Generate, Images & More"},"content":{"rendered":"\n

In this tutorial, I will show you how to use hyperlinks in SQL Server tables. You will learn how to create hyperlinks for text and images, generate, and also manipulate hyperlinks in SQL Server.<\/p>\n\n\n\n

Before we get started, let’s learn about hyperlinks.<\/p>\n\n\n\n

A Hyperlink is a clickable digital reference to data. It takes a user from one digital location to another. You can read more about hyperlinks on Wikipedia<\/a>.<\/p>\n\n\n\n

The syntax of a hyperlink in HTML looks like this:<\/p>\n\n\n\n

<a href=\"URL\" title=\"link title\" target=\"link target\" class=\"link class\">link label<\/a><\/code><\/pre>\n\n\n\n

For the purpose of this tutorial, let’s also see the HTML syntax for images.<\/p>\n\n\n\n

<img src=\"URL\" alt=\"Image Title\" width=\"X\" height=\"Y\"><\/code><\/pre>\n\n\n\n

Now that we understand hyperlink syntax IN HTML, how do we create them in SQL? Let’s get started.<\/p>\n\n\n\n

How to add hyperlinks in SQL Server<\/h2>\n\n\n\n

Let’s start by adding a hyperlink column to a table.<\/p>\n\n\n\n

ALTER TABLE table_name\r\nADD hyperlink_column VARCHAR(255);<\/code><\/pre>\n\n\n\n

This code will add a new column “hyperlink_column” column to “table_name” table.<\/p>\n\n\n\n

How to insert hyperlink in SQL query<\/h2>\n\n\n\n

To insert a hyperlink into the column we just created, the SQL query is as follows:<\/p>\n\n\n\n

INSERT INTO table_name (hyperlink_column)\r\nVALUES ('<a href=\"URL\" title=\"link title\" target=\"link target\" class=\"link class\">link label<\/a>')<\/code><\/pre>\n\n\n\n

Here’s my resultset.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

How to replace a text column as hyperlink<\/h2>\n\n\n\n

You can also update existing text columns as hyperlinks using this code.<\/p>\n\n\n\n

UPDATE table_name\r\nSET hyperlink_column = CONCAT('<a href=\"'+[url_column]+'\"'\n,' title=\"' + [title_column] + '\"'\n,' target=\"' + [target_column] + '\"'\n,' class=\"' + [class_column] + '\"'\n, '>'\n, [text_column]\n, '<\/a>') \nwhere id = 1<\/code><\/pre>\n\n\n\n

How to generate hyperlinks in SQL query<\/h2>\n\n\n\n

Now let’s consider a situation where you need to combine columns to generate a hyperlink in SQL Server.<\/p>\n\n\n\n

SELECT\r\n'<a href=\"'+[url_column]+'\"'\r\n+' title=\"' + [title_column] + '\"'\r\n+' target=\"' + [target_column] + '\"'\r\n+' class=\"' + [class_column] + '\"'\r\n+ '>'\r\n+ [text_column]\r\n+ '<\/a>' AS hyperlink_column\r\nFROM table_name<\/code><\/pre>\n\n\n\n

Alternatively, you can use the CONCAT function.<\/p>\n\n\n\n

SELECT\r\nCONCAT('<a href=\"'+[url_column]+'\"'\r\n,' title=\"' + [title_column] + '\"'\r\n,' target=\"' + [target_column] + '\"'\r\n,' class=\"' + [class_column] + '\"'\r\n, '>'\r\n, [text_column]\r\n, '<\/a>') AS hyperlink_column\r\nFROM table_name<\/code><\/pre>\n\n\n\n

How to generate hyperlinks in SQL query that opens in a new page<\/h2>\n\n\n\n

There was a time I was generating my URLs in SQL for SSRS reporting. When clicking the links on the web page, the URL opens on the same page. However, users needed the reports to open on another tab.<\/p>\n\n\n\n

This is a simple fix. To do this, add or change the target value to “_blank”. <\/p>\n\n\n\n

SELECT\nCONCAT('<a href=\"'+[url_column]+'\"'\n,' title=\"' + [title_column] + '\"'\n,' target=\"_blank<\/strong>\"'\n,' class=\"' + [class_column] + '\"'\n, '>'\n, [text_column]\n, '<\/a>') AS hyperlink_column\nFROM table_name<\/code><\/pre>\n\n\n\n

This attribute and value (target=”_blank”) make your hyperlink open in a new tab on your web browser.<\/p>\n\n\n\n

How to generate image URL in SQL server<\/h2>\n\n\n\n

This is similar to generating hyperlinks. The difference is the syntax for images is different. Using the CONCAT SQL Server function, you can generate an image URL as follows:<\/p>\n\n\n\n

SELECT\r\nCONCAT('<img src=\"'+[src_column]+'\"'\r\n,' alt=\"' + [alt_column] + '\"'\r\n,' width=\"' + [width_column] + '\"'\r\n,' height=\"' + [height_column] + '\"'\r\n, '>') AS image_column\r\nFROM table_name<\/code><\/pre>\n\n\n\n

I hope you found this article helpful. To learn more, check out my SQL<\/a> section.<\/p>\n","protected":false},"excerpt":{"rendered":"

In this tutorial, I will show you how to use hyperlinks in SQL Server tables. You will learn how to … <\/p>\n

Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":440,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,12],"tags":[],"yoast_head":"\nHyperlinks in SQL Server - Insert, Generate, Images & More - grionic<\/title>\n<meta name=\"description\" content=\"Learn how to insert, update, generate hyperlinks in SQL Server using the CONCAT function and other SQL techniques.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Hyperlinks in SQL Server - Insert, Generate, Images & More - grionic\" \/>\n<meta property=\"og:description\" content=\"Learn how to insert, update, generate hyperlinks in SQL Server using the CONCAT function and other SQL techniques.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"grionic\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T19:53:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-29T19:54:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"AJ\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"AJ\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/\",\"url\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/\",\"name\":\"Hyperlinks in SQL Server - Insert, Generate, Images & More - grionic\",\"isPartOf\":{\"@id\":\"https:\/\/grionic.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png\",\"datePublished\":\"2023-07-28T19:53:25+00:00\",\"dateModified\":\"2023-07-29T19:54:20+00:00\",\"author\":{\"@id\":\"https:\/\/grionic.com\/#\/schema\/person\/c573f60fbeba4ce8155d576d0819ffb8\"},\"description\":\"Learn how to insert, update, generate hyperlinks in SQL Server using the CONCAT function and other SQL techniques.\",\"breadcrumb\":{\"@id\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#primaryimage\",\"url\":\"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png\",\"contentUrl\":\"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png\",\"width\":1920,\"height\":1080,\"caption\":\"hyperlinks in sql server\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/grionic.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hyperlinks in SQL Server – Insert, Generate, Images & More\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/grionic.com\/#website\",\"url\":\"https:\/\/grionic.com\/\",\"name\":\"grionic\",\"description\":\"Learn Data Analysis Tools & Techniques\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/grionic.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/grionic.com\/#\/schema\/person\/c573f60fbeba4ce8155d576d0819ffb8\",\"name\":\"AJ\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/grionic.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/431e89db69ae98f2296a504b802f302b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/431e89db69ae98f2296a504b802f302b?s=96&d=mm&r=g\",\"caption\":\"AJ\"},\"sameAs\":[\"https:\/\/grionic.com\"],\"url\":\"https:\/\/grionic.com\/author\/oluwatosin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Hyperlinks in SQL Server - Insert, Generate, Images & More - grionic","description":"Learn how to insert, update, generate hyperlinks in SQL Server using the CONCAT function and other SQL techniques.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"Hyperlinks in SQL Server - Insert, Generate, Images & More - grionic","og_description":"Learn how to insert, update, generate hyperlinks in SQL Server using the CONCAT function and other SQL techniques.","og_url":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/","og_site_name":"grionic","article_published_time":"2023-07-28T19:53:25+00:00","article_modified_time":"2023-07-29T19:54:20+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png","type":"image\/png"}],"author":"AJ","twitter_card":"summary_large_image","twitter_misc":{"Written by":"AJ","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/","url":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/","name":"Hyperlinks in SQL Server - Insert, Generate, Images & More - grionic","isPartOf":{"@id":"https:\/\/grionic.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#primaryimage"},"image":{"@id":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png","datePublished":"2023-07-28T19:53:25+00:00","dateModified":"2023-07-29T19:54:20+00:00","author":{"@id":"https:\/\/grionic.com\/#\/schema\/person\/c573f60fbeba4ce8155d576d0819ffb8"},"description":"Learn how to insert, update, generate hyperlinks in SQL Server using the CONCAT function and other SQL techniques.","breadcrumb":{"@id":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/grionic.com\/hyperlinks-in-sql-server\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#primaryimage","url":"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png","contentUrl":"https:\/\/grionic.com\/wp-content\/uploads\/2023\/07\/hyperlinks-in-sql-server.png","width":1920,"height":1080,"caption":"hyperlinks in sql server"},{"@type":"BreadcrumbList","@id":"https:\/\/grionic.com\/hyperlinks-in-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/grionic.com\/"},{"@type":"ListItem","position":2,"name":"Hyperlinks in SQL Server – Insert, Generate, Images & More"}]},{"@type":"WebSite","@id":"https:\/\/grionic.com\/#website","url":"https:\/\/grionic.com\/","name":"grionic","description":"Learn Data Analysis Tools & Techniques","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/grionic.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/grionic.com\/#\/schema\/person\/c573f60fbeba4ce8155d576d0819ffb8","name":"AJ","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/grionic.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/431e89db69ae98f2296a504b802f302b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/431e89db69ae98f2296a504b802f302b?s=96&d=mm&r=g","caption":"AJ"},"sameAs":["https:\/\/grionic.com"],"url":"https:\/\/grionic.com\/author\/oluwatosin\/"}]}},"_links":{"self":[{"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/posts\/438"}],"collection":[{"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/comments?post=438"}],"version-history":[{"count":1,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/posts\/438\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/posts\/438\/revisions\/441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/media\/440"}],"wp:attachment":[{"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/media?parent=438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/categories?post=438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grionic.com\/wp-json\/wp\/v2\/tags?post=438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}