{"id":13534,"date":"2024-03-15T07:20:03","date_gmt":"2024-03-15T07:20:03","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/"},"modified":"2025-08-05T19:50:29","modified_gmt":"2025-08-05T19:50:29","slug":"how-to-replace-numbers-in-a-string-with-sql-server","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/","title":{"rendered":"SQL Server: Remove Numbers from String"},"content":{"rendered":"<p>In SQL Server, the REPLACE function can be used to replace numbers in a string.<\/p>\n<p>Here is an example:<\/p>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">DECLARE<\/span> <span class=\"hljs-variable\">@str<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-string\">'abc123xyz456'<\/span>\r\n<span class=\"hljs-keyword\">DECLARE<\/span> <span class=\"hljs-variable\">@newStr<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>)\r\n\r\n<span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-variable\">@newStr<\/span> <span class=\"hljs-operator\">=<\/span> REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(<span class=\"hljs-variable\">@str<\/span>,\r\n    <span class=\"hljs-string\">'0'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'1'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'2'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'3'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'4'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'5'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'6'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'7'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'8'<\/span>, <span class=\"hljs-string\">''<\/span>), <span class=\"hljs-string\">'9'<\/span>, <span class=\"hljs-string\">''<\/span>)\r\n\r\n<span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-variable\">@newStr<\/span>\r\n<\/code><\/pre>\n<p>Running the example code above will replace the numbers in the string &#8220;abc123xyz456&#8221; with an empty string, resulting in &#8220;abcxyz&#8221;.<\/p>\n<p>In the REPLACE function, we used multiple instances of the REPLACE function consecutively to replace each digit in the string. Initially, we replaced the digit 0 with an empty string, then replaced 1 with an empty string, and so on up to 9. This way, the final result is a string without any digits.<\/p>\n<p>It is important to note that the above examples can only replace numeric characters in the string. If the string contains any characters other than numeric characters, they will not be replaced. If you need to replace other characters in the string, you can specify the characters to be replaced in the first parameter of the REPLACE function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In SQL Server, the REPLACE function can be used to replace numbers in a string. Here is an example: DECLARE @str VARCHAR(50) = &#8216;abc123xyz456&#8217; DECLARE @newStr VARCHAR(50) SELECT @newStr = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@str, &#8216;0&#8217;, &#8221;), &#8216;1&#8217;, &#8221;), &#8216;2&#8217;, &#8221;), &#8216;3&#8217;, &#8221;), &#8216;4&#8217;, &#8221;), &#8216;5&#8217;, &#8221;), &#8216;6&#8217;, &#8221;), &#8216;7&#8217;, &#8221;), &#8216;8&#8217;, &#8221;), &#8216;9&#8217;, &#8221;) SELECT @newStr Running the [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[18051,18050,6078,572,13489],"class_list":["post-13534","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-remove-digits","tag-remove-numbers-from-string","tag-replace-function","tag-sql-server","tag-sql-string-manipulation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server: Remove Numbers from String - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Learn how to remove all numbers from a string using SQL Server&#039;s REPLACE function. Includes practical code example.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server: Remove Numbers from String\" \/>\n<meta property=\"og:description\" content=\"Learn how to remove all numbers from a string using SQL Server&#039;s REPLACE function. Includes practical code example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-15T07:20:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-05T19:50:29+00:00\" \/>\n<meta name=\"author\" content=\"Ava Mitchell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ava Mitchell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\"},\"author\":{\"name\":\"Ava Mitchell\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64\"},\"headline\":\"SQL Server: Remove Numbers from String\",\"datePublished\":\"2024-03-15T07:20:03+00:00\",\"dateModified\":\"2025-08-05T19:50:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\"},\"wordCount\":155,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"remove digits\",\"remove numbers from string\",\"REPLACE function\",\"sql server\",\"SQL string manipulation\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\",\"name\":\"SQL Server: Remove Numbers from String - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-15T07:20:03+00:00\",\"dateModified\":\"2025-08-05T19:50:29+00:00\",\"description\":\"Learn how to remove all numbers from a string using SQL Server's REPLACE function. Includes practical code example.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server: Remove Numbers from String\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64\",\"name\":\"Ava Mitchell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g\",\"caption\":\"Ava Mitchell\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/avamitchell\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server: Remove Numbers from String - Blog - Silicon Cloud","description":"Learn how to remove all numbers from a string using SQL Server's REPLACE function. Includes practical code example.","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:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server: Remove Numbers from String","og_description":"Learn how to remove all numbers from a string using SQL Server's REPLACE function. Includes practical code example.","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-15T07:20:03+00:00","article_modified_time":"2025-08-05T19:50:29+00:00","author":"Ava Mitchell","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Ava Mitchell","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/"},"author":{"name":"Ava Mitchell","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64"},"headline":"SQL Server: Remove Numbers from String","datePublished":"2024-03-15T07:20:03+00:00","dateModified":"2025-08-05T19:50:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/"},"wordCount":155,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["remove digits","remove numbers from string","REPLACE function","sql server","SQL string manipulation"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/","name":"SQL Server: Remove Numbers from String - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-15T07:20:03+00:00","dateModified":"2025-08-05T19:50:29+00:00","description":"Learn how to remove all numbers from a string using SQL Server's REPLACE function. Includes practical code example.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-replace-numbers-in-a-string-with-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL Server: Remove Numbers from String"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64","name":"Ava Mitchell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g","caption":"Ava Mitchell"},"url":"https:\/\/www.silicloud.com\/blog\/author\/avamitchell\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/13534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=13534"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/13534\/revisions"}],"predecessor-version":[{"id":157526,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/13534\/revisions\/157526"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=13534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=13534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=13534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}