{"id":104247,"date":"2021-08-23T11:00:00","date_gmt":"2021-08-23T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=104247"},"modified":"2022-02-23T20:10:49","modified_gmt":"2022-02-23T18:10:49","slug":"sql-substring-function","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/","title":{"rendered":"SQL SUBSTRING Function"},"content":{"rendered":"<p>In this article, we&#8217;re going to explain the SUBSTRING function in SQL. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>The SUBSTRING function is available in SQL Server (from 2008 edition) and MySQL (from version 4.0) as a part of String functions. <\/p>\n<p>Using this function we&#8217;re able to manipulate strings directly with a SQL query. Also, in combination with other functions and procedures, the SUBSTRING function is a great tool introduced in the SQL environment.<\/p>\n<p>In the next sections, we&#8217;ll see more about the syntax and some important knowledge about how to this function.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-1-1-pre-requisites\">1.1 Pre-requisites<\/h3>\n<p>You need to have at least SQL Server 2008 edition or above for the examples shown in this article. Also, you can use MySQL starting on 4.0, but I recommend using version 8.0 or later.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-substring-syntax\">2. SUBSTRING syntax<\/h2>\n<p>The function is called in a T-SQL instruction like this: <code>SUBSTRING(string,&nbsp;start,&nbsp;length).<\/code> Below, I explain each parameter present in the function.<\/p>\n<ul class=\"wp-block-list\">\n<li>string &#8211; the string to extract from.<\/li>\n<li>start &#8211; the start position to extract from string. The first position is 1 as default.<\/li>\n<li>length &#8211; the number of characters to extract. Must be a positive number.<\/li>\n<\/ul>\n<p>In SQL Server, all these parameters are required to use the SUBSTRING function. A simple example is shown next:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING<\/em><\/span><\/p>\n<pre class=\"brush:sql\">SELECT SUBSTRING('Java Code Geeks',1,4)\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/simple_result_substring.png\"><img decoding=\"async\" width=\"350\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/simple_result_substring.png\" alt=\"sql substring - result\" class=\"wp-image-104283\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/simple_result_substring.png 350w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/simple_result_substring-300x171.png 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption>SUBSTRING result<\/figcaption><\/figure>\n<\/div>\n<p>For MySQL, we need to insert at least the <strong>string<\/strong> and <strong>start<\/strong> parameters to work. If we don&#8217;t specify the <strong>length,<\/strong> the function will return from the position passed as the <strong>start<\/strong> position to the last string character.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING without length<\/em><\/span><\/p>\n<pre class=\"brush:sql\">SELECT SUBSTRING('Java Code Geeks',4)\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/result_without_length.png\"><img decoding=\"async\" width=\"350\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/result_without_length.png\" alt=\"sql substring - mysql no length\" class=\"wp-image-104284\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/result_without_length.png 350w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/result_without_length-300x171.png 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption>MySQL result without length<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-3-using-substring\">3. Using SUBSTRING<\/h2>\n<p>Now, we&#8217;ll do some hands-on with the <code>SUBSTRING<\/code> function. In the next steps, we&#8217;re going to see how to scan the string together with other functions.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-1-using-with-a-character-string\">3.1 Using with a character string<\/h3>\n<p>A good reason to use the <code>SUBSTRING<\/code> function is to find some value in the string and return it to a new string. The example below is a parse for an email where we can qualify the recipient, domain, and full domain. Should work fine in SQL Server.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING with character<\/em><\/span><\/p>\n<pre class=\"brush:sql\">with substring_example as (select email='sergio.lauriano@javacodegeeks.com')\n \nselect email\n, recipient = SUBSTRING(email,1, CHARINDEX('@',email,1) -1)\n, fulldomain = SUBSTRING(email, CHARINDEX('@',email,1) +1, LEN(email))\n, domainname = SUBSTRING(email, CHARINDEX('@',email,1) +1, CHARINDEX('.',email,CHARINDEX('@',email,1)) - CHARINDEX('@',email,1))\n, toplevel = SUBSTRING(email, CHARINDEX('.',email,CHARINDEX('@',email,1)) +1, LEN(email))\nfrom substring_example<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_result_char.png\"><img decoding=\"async\" width=\"600\" height=\"150\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_result_char.png\" alt=\"sql substring - char result\" class=\"wp-image-104329\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_result_char.png 600w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_result_char-300x75.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption>SQL Server SUBSTRING char result<\/figcaption><\/figure>\n<\/div>\n<p>Note that we&#8217;ve used the <code>CHARINDEX<\/code> function to put boards to the string extraction. Firstly, we define the &#8216;@&#8217; character to find its position in the string to define the <strong>recipient.<\/strong> <\/p>\n<p>Next, we used the char position to determine the start of the <strong>full domain<\/strong>. Later, we combine the &#8216;@&#8217; character as the start and &#8216;.&#8217; character as the end to extract the <strong>domain name.<\/strong>  <\/p>\n<p>Finally, the <strong>top-level <\/strong>is find from the &#8216;.&#8217; character until the end of the string.<\/p>\n<p>In MySQL, we can use the POSITION function as an alternative to extract the character substring.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING with character in MySQL<\/em><\/span><\/p>\n<pre class=\"brush:sql\">set @email = \"sergio.lauriano@javacodegeeks.com\";\nselect SUBSTRING(@email,1,POSITION(\"@\" IN @email)-1) as recipient, \nSUBSTRING(@email,POSITION(\"@\" IN @email)+1,length(@email)) as fulldomain,\nSUBSTRING(@email,POSITION(\"@\" IN @email) + 1,POSITION(\".\" IN substring(@email,POSITION(\"@\" IN @email) + 1))-1) as domainname,\nSUBSTRING(substring(@email,POSITION(\"@\" IN @email) + 1),POSITION(\".\" IN substring(@email,POSITION(\"@\" IN @email) + 1))+1,length(@email)) as toplevel;\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysq_char_result.png\"><img decoding=\"async\" width=\"420\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysq_char_result.png\" alt=\"\" class=\"wp-image-104334\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysq_char_result.png 420w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysq_char_result-300x143.png 300w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/a><figcaption>MySQL SUBSTRING char result<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-3-2-using-text-and-ntext\">3.2 Using text and ntext<\/h3>\n<p>We can also handle table fields with <code>SUBSTRING<\/code> function. The varchar (text and ntext) data type can be used with the function and in the next example, we&#8217;ll do the same manipulation as the previous, but using a table field.<\/p>\n<p>We&#8217;ll use the below table to manipulate the field CustomerMail.<\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><strong>CustomerID<\/strong><\/td>\n<td><strong>CustomerName<\/strong><\/td>\n<td><strong>ContactName<\/strong><\/td>\n<td><strong>ContactMail<\/strong><\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>Tampa Bay Buccaneers<\/td>\n<td>Tom Brady<\/td>\n<td>tom.brady@buccaneers.com<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>New England Patriots<\/td>\n<td>NULL<\/td>\n<td>contact@patriots.com<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Dallas Cowboys<\/td>\n<td>Dak Prescott<\/td>\n<td>dak.prescott@cowboys.net<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Kansas City Chiefs<\/td>\n<td>Patrick Mahomes<\/td>\n<td>pmahomes@kcchiefs.com<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>New Orleans Saints<\/td>\n<td>NULL<\/td>\n<td>contact@saints.com<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Customers table<\/figcaption><\/figure>\n<p>In SQL Server, we just point to the required field that we want to manipulate. The result should be the same as using a simple varchar variable.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING with varchar in SQL Server<\/em><\/span><\/p>\n<pre class=\"brush:sql\">select ContactMail as email\n, SUBSTRING(ContactMail,1, CHARINDEX('@',ContactMail,1) -1) as recipient\n, SUBSTRING(ContactMail, CHARINDEX('@',ContactMail,1) +1, LEN(ContactMail)) as fulldomain\n, SUBSTRING(ContactMail, CHARINDEX('@',ContactMail,1) +1, CHARINDEX('.',ContactMail,CHARINDEX('@',ContactMail,1)) - CHARINDEX('@',ContactMail,1)) as domainname\n, SUBSTRING(ContactMail, CHARINDEX('.',ContactMail,CHARINDEX('@',ContactMail,1)) +1, LEN(ContactMail)) as toplevel\nfrom Customers<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/varchar_sql_server_result.png\"><img decoding=\"async\" width=\"500\" height=\"220\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/varchar_sql_server_result.png\" alt=\"\" class=\"wp-image-104333\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/varchar_sql_server_result.png 500w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/varchar_sql_server_result-300x132.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption>SQL Server varchar result<\/figcaption><\/figure>\n<\/div>\n<p>In MySQL, we do the same move keeping the script pretty similar to the previous.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING with varchar in MySQL<\/em><\/span><\/p>\n<pre class=\"brush:sql\">select SUBSTRING(ContactMail,1,POSITION(\"@\" IN ContactMail)-1) as recipient, \nSUBSTRING(ContactMail,POSITION(\"@\" IN ContactMail)+1,length(ContactMail)) as fulldomain,\nSUBSTRING(ContactMail,POSITION(\"@\" IN ContactMail) + 1,POSITION(\".\" IN substring(ContactMail,POSITION(\"@\" IN ContactMail) + 1))-1) as domainname,\nSUBSTRING(substring(ContactMail,POSITION(\"@\" IN ContactMail) + 1),POSITION(\".\" IN substring(ContactMail,POSITION(\"@\" IN ContactMail) + 1))+1,length(ContactMail)) as toplevel\nfrom Customers;\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysql_varchar_result.png\"><img decoding=\"async\" width=\"420\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysql_varchar_result.png\" alt=\"\" class=\"wp-image-104335\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysql_varchar_result.png 420w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/mysql_varchar_result-300x143.png 300w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/a><figcaption>MySQL varchar result<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-3-3-using-image\">3.3 Using image<\/h3>\n<p>In the next example, we&#8217;re dealing with images, that in SQL Server is stored as a <strong>varbinary<\/strong>. The varbinary type is a hex byte representation of a file. <\/p>\n<p>I created the MyImages table where some images and they&#8217;re present the following data in a simple query.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/image_result.png\"><img decoding=\"async\" width=\"520\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/image_result.png\" alt=\"\" class=\"wp-image-104336\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/image_result.png 520w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/image_result-300x115.png 300w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><\/a><figcaption>Image varbinary in table MyImages<\/figcaption><\/figure>\n<\/div>\n<p>Using the <code>SUBSTRING<\/code> function, we can retrieve the first 10 bytes of these data using the following query:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Using SUBSTRING with varchar in MySQL<\/em><\/span><\/p>\n<pre class=\"brush:sql\">select SUBSTRING(img,1,10) as imageOutput from MyImages\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_image_result.png\"><img decoding=\"async\" width=\"400\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_image_result.png\" alt=\"\" class=\"wp-image-104337\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_image_result.png 400w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/substring_image_result-300x150.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption>SUBSTRING image result<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-4-conclusion\">4. Conclusion<\/h2>\n<p>In conclusion, we saw how to use the SUBSTRING function in SQL Server and MySQL. Also, we could understand its syntax in each environment.<\/p>\n<p>Further, we can do some examples together with other functions to extract data from a string and also fields from tables. Finally, we could see in a SQL Server example how the SUBSTRING function can return image bytes data.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-5-download-the-source-code\">5. Download the source code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/sql_substring.zip\"><strong>SQL SUBSTRING Function<\/strong><\/a><\/div>\n<p><strong>Last updated on Feb. 23rd, 2022<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we&#8217;re going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008 edition) and MySQL (from version 4.0) as a part of String functions. Using this function we&#8217;re able to manipulate strings directly with a SQL query. Also, in combination with other functions &hellip;<\/p>\n","protected":false},"author":239,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[647,46734,241,1205],"class_list":["post-104247","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-mysql","tag-sqlserver","tag-string-2","tag-substring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL SUBSTRING Function - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article, we&#039;re going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL SUBSTRING Function - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article, we&#039;re going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-23T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-23T18:10:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sergio Lauriano Junior\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sergiolauriano\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sergio Lauriano Junior\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\"},\"author\":{\"name\":\"Sergio Lauriano Junior\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe\"},\"headline\":\"SQL SUBSTRING Function\",\"datePublished\":\"2021-08-23T08:00:00+00:00\",\"dateModified\":\"2022-02-23T18:10:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\"},\"wordCount\":772,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"mysql\",\"sqlserver\",\"string\",\"substring\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\",\"name\":\"SQL SUBSTRING Function - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2021-08-23T08:00:00+00:00\",\"dateModified\":\"2022-02-23T18:10:49+00:00\",\"description\":\"In this article, we're going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL SUBSTRING Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe\",\"name\":\"Sergio Lauriano Junior\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg\",\"caption\":\"Sergio Lauriano Junior\"},\"description\":\"Sergio is graduated in Software Development in the University City of S\u00e3o Paulo (UNICID). During his career, he get involved in a large number of projects such as telecommunications, billing, data processing, health and financial services. Currently, he works in financial area using mainly Java and IBM technologies.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sergio-lauriano\/\",\"https:\/\/x.com\/@sergiolauriano\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/sergio-lauriano\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL SUBSTRING Function - Java Code Geeks","description":"In this article, we're going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008","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:\/\/examples.javacodegeeks.com\/sql-substring-function\/","og_locale":"en_US","og_type":"article","og_title":"SQL SUBSTRING Function - Java Code Geeks","og_description":"In this article, we're going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008","og_url":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-08-23T08:00:00+00:00","article_modified_time":"2022-02-23T18:10:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Sergio Lauriano Junior","twitter_card":"summary_large_image","twitter_creator":"@sergiolauriano","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Sergio Lauriano Junior","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/"},"author":{"name":"Sergio Lauriano Junior","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe"},"headline":"SQL SUBSTRING Function","datePublished":"2021-08-23T08:00:00+00:00","dateModified":"2022-02-23T18:10:49+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/"},"wordCount":772,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["mysql","sqlserver","string","substring"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/","url":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/","name":"SQL SUBSTRING Function - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2021-08-23T08:00:00+00:00","dateModified":"2022-02-23T18:10:49+00:00","description":"In this article, we're going to explain the SUBSTRING function in SQL. 1. Introduction The SUBSTRING function is available in SQL Server (from 2008","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/sql-substring-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/sql-substring-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL SUBSTRING Function"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe","name":"Sergio Lauriano Junior","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg","caption":"Sergio Lauriano Junior"},"description":"Sergio is graduated in Software Development in the University City of S\u00e3o Paulo (UNICID). During his career, he get involved in a large number of projects such as telecommunications, billing, data processing, health and financial services. Currently, he works in financial area using mainly Java and IBM technologies.","sameAs":["https:\/\/www.linkedin.com\/in\/sergio-lauriano\/","https:\/\/x.com\/@sergiolauriano"],"url":"https:\/\/examples.javacodegeeks.com\/author\/sergio-lauriano\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/239"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=104247"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104247\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=104247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=104247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=104247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}