{"id":4153,"date":"2024-09-26T06:19:26","date_gmt":"2024-09-25T22:19:26","guid":{"rendered":"https:\/\/five.co\/?p=4153"},"modified":"2026-05-04T15:23:28","modified_gmt":"2026-05-04T07:23:28","slug":"propercase-in-sql","status":"publish","type":"post","link":"https:\/\/preview-php85.dzine.org\/five\/blog\/propercase-in-sql\/","title":{"rendered":"Propercase in SQL: Practical Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>propercase<\/code>, also known as title case, is a text formatting style where the first letter of each word is capitalized. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While it might seem like a simple concept, implementing <code>propercase<\/code> in SQL can be tricky due to the lack of a built-in function in most database systems. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article will guide you through various methods to achieve <code>propercase<\/code> in SQL, complete with practical examples and real-world applications.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div style=\"background-color: #001524;\"><hr style=\"height: 5px;\" \/>\n<pre style=\"text-align: center; overflow: hidden; white-space: pre-line;\"><span style=\"color: #f1ebda; background-color: #4588d8; font-size: calc(25px + 0.390625vw);\"><strong>SQL Made Simple - Try Five<\/strong><br \/><span style=\"font-size: 14pt;\">Five is the Easiest Way to Create, Model and Query a SQL Database<\/span><\/span><\/pre>\n<p style=\"text-align: center;\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\" target=\"_blank\" rel=\"noopener\" data-wplink-edit=\"true\"><button style=\"background-color: #f8b92b; border: none; color: black; padding: 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 18px; cursor: pointer; margin: 4px 2px; border-radius: 5px;\"><strong>Get Started<\/strong><\/button><\/a><br \/><span style=\"color: #ffffff; font-size: revert;\">___<\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong><span style=\"color: #ffffff; text-decoration: underline;\">Here&#8217;s What You Can Do With Five<\/span><\/strong><\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"color: #ffffff;\">Create and Model a SQL Database \u2705<br \/>Write or Build SQL Queries \u2705<br \/>Visualize Queries as Charts or in Dashboards \u2705<br \/>Add CRUD Permissions to Control Data Access \u2705<br \/>Host Your Database Online \u2705\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><span style=\"color: #f1ebda; background-color: #4588d8;\"><em><strong>&#8220;Five bridges the gap between SQL and the web, <br \/>allowing me to create full-stack applications almost entirely in SQL&#8221;<\/strong><\/em><\/span><br \/><span style=\"color: #ffffff;\">&#8211; Crag Jones, Database Administrator (DBA)<\/span><\/p>\n<hr style=\"height: 5px;\" \/><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<div class=\"root-eb-toc-0ynhe wp-block-essential-blocks-table-of-contents\"><div class=\"eb-parent-wrapper eb-parent-eb-toc-0ynhe \"><div class=\"eb-toc-container eb-toc-0ynhe  eb-toc-is-not-sticky eb-toc-not-collapsible eb-toc-initially-not-collapsed eb-toc-scrollToTop style-1 list-style-none\" data-scroll-top=\"false\" data-scroll-top-icon=\"fas fa-angle-up\" data-collapsible=\"false\" data-sticky-hide-mobile=\"false\" data-sticky=\"false\" data-scroll-target=\"scroll_to_toc\" data-copy-link=\"false\" data-editor-type=\"\" data-hide-desktop=\"false\" data-hide-tab=\"false\" data-hide-mobile=\"false\" data-itemcollapsed=\"false\" data-highlight-scroll=\"false\"><div class=\"eb-toc-header\"><h2 class=\"eb-toc-title\">Table of Contents<\/h2><\/div><div class=\"eb-toc-wrapper \" data-headers=\"[{&quot;level&quot;:2,&quot;content&quot;:&quot;Understanding Propercase&quot;,&quot;text&quot;:&quot;Understanding Propercase&quot;,&quot;link&quot;:&quot;understanding-propercase&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Basic Propercase Implementation in SQL&quot;,&quot;text&quot;:&quot;Basic Propercase Implementation in SQL&quot;,&quot;link&quot;:&quot;basic-propercase-implementation-in-sql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Multi-Word Propercase in SQL&quot;,&quot;text&quot;:&quot;Multi-Word Propercase in SQL&quot;,&quot;link&quot;:&quot;multi-word-propercase-in-sql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Handling Exceptions in Propercase&quot;,&quot;text&quot;:&quot;Handling Exceptions in Propercase&quot;,&quot;link&quot;:&quot;handling-exceptions-in-propercase&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Real-World Application: Standardizing Product Names&quot;,&quot;text&quot;:&quot;Real-World Application: Standardizing Product Names&quot;,&quot;link&quot;:&quot;real-world-application-standardizing-product-names&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Propercase in Different SQL Dialects&quot;,&quot;text&quot;:&quot;Propercase in Different SQL Dialects&quot;,&quot;link&quot;:&quot;propercase-in-different-sql-dialects&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;MySQL&quot;,&quot;text&quot;:&quot;MySQL&quot;,&quot;link&quot;:&quot;mysql&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;PostgreSQL&quot;,&quot;text&quot;:&quot;PostgreSQL&quot;,&quot;link&quot;:&quot;postgresql&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Performance Considerations&quot;,&quot;text&quot;:&quot;Performance Considerations&quot;,&quot;link&quot;:&quot;performance-considerations&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Propercase in Application Logic&quot;,&quot;text&quot;:&quot;Propercase in Application Logic&quot;,&quot;link&quot;:&quot;propercase-in-application-logic&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;Conclusion&quot;,&quot;text&quot;:&quot;Conclusion&quot;,&quot;link&quot;:&quot;conclusion&quot;},{&quot;level&quot;:2,&quot;content&quot;:&quot;FAQ&quot;,&quot;text&quot;:&quot;FAQ&quot;,&quot;link&quot;:&quot;faq&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;What is \\u201cpropercase\\u201d in SQL?&quot;,&quot;text&quot;:&quot;What is \\u201cpropercase\\u201d in SQL?&quot;,&quot;link&quot;:&quot;what-is-propercase-in-sql&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;How do you implement a basic propercase conversion in SQL?&quot;,&quot;text&quot;:&quot;How do you implement a basic propercase conversion in SQL?&quot;,&quot;link&quot;:&quot;how-do-you-implement-a-basic-propercase-conversion-in-sql&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Can SQL properly handle multi\\u2011word strings for title case?&quot;,&quot;text&quot;:&quot;Can SQL properly handle multi\\u2011word strings for title case?&quot;,&quot;link&quot;:&quot;eb-table-content-14&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;How can exceptions (like \\u201ca\\u201d, \\u201can\\u201d, \\u201cthe\\u201d) be handled in propercase?&quot;,&quot;text&quot;:&quot;How can exceptions (like \\u201ca\\u201d, \\u201can\\u201d, \\u201cthe\\u201d) be handled in propercase?&quot;,&quot;link&quot;:&quot;how-can-exceptions-like-a-an-the-be-handled-in-propercase&quot;},{&quot;level&quot;:3,&quot;content&quot;:&quot;Does propercase work differently in other SQL dialects?&quot;,&quot;text&quot;:&quot;Does propercase work differently in other SQL dialects?&quot;,&quot;link&quot;:&quot;does-propercase-work-differently-in-other-sql-dialects&quot;}]\" data-visible=\"[true,true,true,true,true,true]\" data-delete-headers=\"[{&quot;label&quot;:&quot;Understanding Propercase&quot;,&quot;value&quot;:&quot;understanding-propercase&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Basic Propercase Implementation in SQL&quot;,&quot;value&quot;:&quot;basic-propercase-implementation-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Multi-Word Propercase in SQL&quot;,&quot;value&quot;:&quot;multi-word-propercase-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Handling Exceptions in Propercase&quot;,&quot;value&quot;:&quot;handling-exceptions-in-propercase&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Real-World Application: Standardizing Product Names&quot;,&quot;value&quot;:&quot;real-world-application-standardizing-product-names&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Propercase in Different SQL Dialects&quot;,&quot;value&quot;:&quot;propercase-in-different-sql-dialects&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;MySQL&quot;,&quot;value&quot;:&quot;mysql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;PostgreSQL&quot;,&quot;value&quot;:&quot;postgresql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Performance Considerations&quot;,&quot;value&quot;:&quot;performance-considerations&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Propercase in Application Logic&quot;,&quot;value&quot;:&quot;propercase-in-application-logic&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Conclusion&quot;,&quot;value&quot;:&quot;conclusion&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;FAQ&quot;,&quot;value&quot;:&quot;faq&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;What is \\u201cpropercase\\u201d in SQL?&quot;,&quot;value&quot;:&quot;what-is-propercase-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;How do you implement a basic propercase conversion in SQL?&quot;,&quot;value&quot;:&quot;how-do-you-implement-a-basic-propercase-conversion-in-sql&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Can SQL properly handle multi\\u2011word strings for title case?&quot;,&quot;value&quot;:&quot;can-sql-properly-handle-multi\\u2011word-strings-for-title-case&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;How can exceptions (like \\u201ca\\u201d, \\u201can\\u201d, \\u201cthe\\u201d) be handled in propercase?&quot;,&quot;value&quot;:&quot;how-can-exceptions-like-a-an-the-be-handled-in-propercase&quot;,&quot;isDelete&quot;:false},{&quot;label&quot;:&quot;Does propercase work differently in other SQL dialects?&quot;,&quot;value&quot;:&quot;does-propercase-work-differently-in-other-sql-dialects&quot;,&quot;isDelete&quot;:false}]\" data-smooth=\"true\" data-top-offset=\"\"><div class=\"eb-toc__list-wrap\"><ul class=\"eb-toc__list\"><li><a href=\"#understanding-propercase\">Understanding Propercase<\/a><li><a href=\"#basic-propercase-implementation-in-sql\">Basic Propercase Implementation in SQL<\/a><li><a href=\"#multi-word-propercase-in-sql\">Multi-Word Propercase in SQL<\/a><li><a href=\"#handling-exceptions-in-propercase\">Handling Exceptions in Propercase<\/a><li><a href=\"#real-world-application-standardizing-product-names\">Real-World Application: Standardizing Product Names<\/a><li><a href=\"#propercase-in-different-sql-dialects\">Propercase in Different SQL Dialects<\/a><ul class=\"eb-toc__list\"><li><a href=\"#mysql\">MySQL<\/a><li><a href=\"#postgresql\">PostgreSQL<\/a><\/li><\/ul><li><a href=\"#performance-considerations\">Performance Considerations<\/a><li><a href=\"#propercase-in-application-logic\">Propercase in Application Logic<\/a><li><a href=\"#conclusion\">Conclusion<\/a><li><a href=\"#faq\">FAQ<\/a><ul class=\"eb-toc__list\"><li><a href=\"#what-is-propercase-in-sql\">What is \u201cpropercase\u201d in SQL?<\/a><li><a href=\"#how-do-you-implement-a-basic-propercase-conversion-in-sql\">How do you implement a basic propercase conversion in SQL?<\/a><li><a href=\"#eb-table-content-14\">Can SQL properly handle multi\u2011word strings for title case?<\/a><li><a href=\"#how-can-exceptions-like-a-an-the-be-handled-in-propercase\">How can exceptions (like \u201ca\u201d, \u201can\u201d, \u201cthe\u201d) be handled in propercase?<\/a><li><a href=\"#does-propercase-work-differently-in-other-sql-dialects\">Does propercase work differently in other SQL dialects?<\/a><\/li><\/ul><\/ul><\/div><\/div><\/div><\/div><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding Propercase<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before we dive into SQL implementations, let&#8217;s clarify what we mean by <code>propercase<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first letter of each word is capitalized<\/li>\n\n\n\n<li>All other letters are lowercase<\/li>\n\n\n\n<li>Some words (like &#8220;a&#8221;, &#8220;an&#8221;, &#8220;the&#8221;) might remain lowercase, depending on style rules<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For example, &#8220;the quick brown fox&#8221; becomes &#8220;The Quick Brown Fox&#8221; in <code>propercase<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Propercase Implementation in SQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s start with a simple implementation that capitalizes the first letter of each word:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>SELECT \n    CONCAT(\n        UPPER(LEFT(column_name, 1)),\n        LOWER(SUBSTRING(column_name, 2))\n    ) AS propercase_column\nFROM \n    your_table;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #56B6C2\">CONCAT<\/span><span style=\"color: #ABB2BF\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #56B6C2\">UPPER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">LEFT<\/span><span style=\"color: #ABB2BF\">(column_name, <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">)),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #56B6C2\">LOWER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">SUBSTRING<\/span><span style=\"color: #ABB2BF\">(column_name, <\/span><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    ) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> propercase_column<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    your_table;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This query does the following:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>LEFT(column_name, 1)<\/code> extracts the first character<\/li>\n\n\n\n<li><code>UPPER()<\/code> capitalizes it<\/li>\n\n\n\n<li><code>SUBSTRING(column_name, 2)<\/code> gets the rest of the string<\/li>\n\n\n\n<li><code>LOWER()<\/code> converts it to lowercase<\/li>\n\n\n\n<li><code>CONCAT()<\/code> joins these parts<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">While this works for single words, it falls short for multi-word strings. Let&#8217;s tackle that next.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Multi-Word Propercase in SQL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For multi-word strings, we need to split the string, apply our <code>propercase<\/code> logic, and then recombine. Here&#8217;s how we can do it in SQL Server:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>CREATE FUNCTION dbo.ProperCase(@Text AS VARCHAR(8000))\nRETURNS VARCHAR(8000)\nAS\nBEGIN\n    DECLARE @Reset BIT;\n    DECLARE @Ret VARCHAR(8000);\n    DECLARE @i INT;\n    DECLARE @c CHAR(1);\n\n    SELECT @Reset = 1, @i = 1, @Ret = '';\n\n    WHILE (@i &lt;= LEN(@Text))\n    SELECT @c = SUBSTRING(@Text, @i, 1),\n           @Ret = @Ret + CASE WHEN @Reset = 1 THEN UPPER(@c) ELSE LOWER(@c) END,\n           @Reset = CASE WHEN @c LIKE '&#091;a-zA-Z&#093;' THEN 0 ELSE 1 END,\n           @i = @i + 1\n    RETURN @Ret\nEND<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">FUNCTION<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">dbo<\/span><span style=\"color: #ABB2BF\">.ProperCase(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">RETURNS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">AS<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">BEGIN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">BIT<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@i<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@c<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">CHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #E06C75\">@i<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">WHILE<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #E06C75\">@i<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">&lt;=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">LEN<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@c<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">SUBSTRING<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #E06C75\">@i<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">           <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> + <\/span><span style=\"color: #C678DD\">CASE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">WHEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">UPPER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@c<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">ELSE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">LOWER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@c<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">           <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">CASE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">WHEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@c<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">LIKE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;&#091;a-zA-Z&#093;&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">ELSE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">           <\/span><span style=\"color: #E06C75\">@i<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@i<\/span><span style=\"color: #ABB2BF\"> + <\/span><span style=\"color: #D19A66\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">RETURN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Ret<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">END<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This function iterates through each character, capitalizing the first letter of each word and lowercasing the rest. You can use it like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>SELECT dbo.ProperCase('the quick brown fox') AS propercase_text;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">dbo<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">ProperCase<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #98C379\">&#39;the quick brown fox&#39;<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> propercase_text;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Output: &#8220;The Quick Brown Fox&#8221;<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Handling Exceptions in Propercase<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In real-world scenarios, you might want to keep certain words lowercase. Let&#8217;s modify our function to handle this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>CREATE FUNCTION dbo.ProperCaseWithExceptions(@Text AS VARCHAR(8000))\nRETURNS VARCHAR(8000)\nAS\nBEGIN\n    DECLARE @Reset BIT;\n    DECLARE @Ret VARCHAR(8000);\n    DECLARE @Word VARCHAR(100);\n    DECLARE @Exceptions TABLE (Word VARCHAR(20));\n\n    INSERT INTO @Exceptions VALUES ('a'),('an'),('the'),('in'),('of'),('to');\n\n    SELECT @Reset = 1, @Ret = '';\n\n    WHILE LEN(@Text) > 0\n    BEGIN\n        SET @Word = LEFT(@Text, ISNULL(NULLIF(CHARINDEX(' ', @Text), 0), LEN(@Text)));\n        SET @Text = SUBSTRING(@Text, LEN(@Word) + 2, 8000);\n\n        IF @Word NOT IN (SELECT Word FROM @Exceptions) OR @Reset = 1\n            SET @Word = UPPER(LEFT(@Word, 1)) + LOWER(SUBSTRING(@Word, 2, LEN(@Word)));\n        ELSE\n            SET @Word = LOWER(@Word);\n\n        SET @Ret = @Ret + @Word + ' ';\n        SET @Reset = 0;\n    END\n\n    RETURN RTRIM(@Ret);\nEND<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">FUNCTION<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">dbo<\/span><span style=\"color: #ABB2BF\">.ProperCaseWithExceptions(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">RETURNS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">AS<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">BEGIN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">BIT<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">100<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Exceptions<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> (Word <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">20<\/span><span style=\"color: #ABB2BF\">));<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">INSERT INTO<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Exceptions<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VALUES<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #98C379\">&#39;a&#39;<\/span><span style=\"color: #ABB2BF\">),(<\/span><span style=\"color: #98C379\">&#39;an&#39;<\/span><span style=\"color: #ABB2BF\">),(<\/span><span style=\"color: #98C379\">&#39;the&#39;<\/span><span style=\"color: #ABB2BF\">),(<\/span><span style=\"color: #98C379\">&#39;in&#39;<\/span><span style=\"color: #ABB2BF\">),(<\/span><span style=\"color: #98C379\">&#39;of&#39;<\/span><span style=\"color: #ABB2BF\">),(<\/span><span style=\"color: #98C379\">&#39;to&#39;<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">WHILE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">LEN<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #56B6C2\">&gt;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">BEGIN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">LEFT<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #56B6C2\">ISNULL<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">NULLIF<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">CHARINDEX<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #98C379\">&#39; &#39;<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">), <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\">), <\/span><span style=\"color: #56B6C2\">LEN<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">)));<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">SUBSTRING<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Text<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #56B6C2\">LEN<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\">) + <\/span><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">8000<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">IF<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">NOT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">IN<\/span><span style=\"color: #ABB2BF\"> (<\/span><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> Word <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Exceptions<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">OR<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">            <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">UPPER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">LEFT<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">)) + <\/span><span style=\"color: #56B6C2\">LOWER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">SUBSTRING<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #56B6C2\">LEN<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\">)));<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">ELSE<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">            <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">LOWER<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\"> + <\/span><span style=\"color: #E06C75\">@Word<\/span><span style=\"color: #ABB2BF\"> + <\/span><span style=\"color: #98C379\">&#39; &#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #E06C75\">@Reset<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">END<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">RETURN<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">RTRIM<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #E06C75\">@Ret<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">END<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This enhanced version keeps specified words lowercase unless they&#8217;re at the beginning of the string.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Real-World Application: Standardizing Product Names<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s apply our propercase function to a real-world scenario: standardizing product names in an e-commerce database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine you have a table <code>Products<\/code> with inconsistently formatted names:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>CREATE TABLE Products (\n    ProductID INT PRIMARY KEY,\n    ProductName VARCHAR(100)\n);\n\nINSERT INTO Products VALUES \n(1, 'DELUXE COFFEE MAKER'),\n(2, 'stainless steel water bottle'),\n(3, 'Organic green TEA'),\n(4, 'MEMORY foam PILLOW');<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">TABLE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">Products<\/span><span style=\"color: #ABB2BF\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    ProductID <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">PRIMARY KEY<\/span><span style=\"color: #ABB2BF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    ProductName <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">100<\/span><span style=\"color: #ABB2BF\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">INSERT INTO<\/span><span style=\"color: #ABB2BF\"> Products <\/span><span style=\"color: #C678DD\">VALUES<\/span><span style=\"color: #ABB2BF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;DELUXE COFFEE MAKER&#39;<\/span><span style=\"color: #ABB2BF\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;stainless steel water bottle&#39;<\/span><span style=\"color: #ABB2BF\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">3<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;Organic green TEA&#39;<\/span><span style=\"color: #ABB2BF\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">4<\/span><span style=\"color: #ABB2BF\">, <\/span><span style=\"color: #98C379\">&#39;MEMORY foam PILLOW&#39;<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We can use our propercase function to standardize these names:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>UPDATE Products\nSET ProductName = dbo.ProperCaseWithExceptions(ProductName);\n\nSELECT * FROM Products;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">UPDATE<\/span><span style=\"color: #ABB2BF\"> Products<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> ProductName <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">dbo<\/span><span style=\"color: #ABB2BF\">.<\/span><span style=\"color: #D19A66\">ProperCaseWithExceptions<\/span><span style=\"color: #ABB2BF\">(ProductName);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> * <\/span><span style=\"color: #C678DD\">FROM<\/span><span style=\"color: #ABB2BF\"> Products;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Output:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>ProductID | ProductName\n1         | Deluxe Coffee Maker\n2         | Stainless Steel Water Bottle\n3         | Organic Green Tea\n4         | Memory Foam Pillow<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">ProductID | ProductName<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">         | Deluxe Coffee Maker<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D19A66\">2<\/span><span style=\"color: #ABB2BF\">         | Stainless Steel Water Bottle<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D19A66\">3<\/span><span style=\"color: #ABB2BF\">         | Organic Green Tea<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D19A66\">4<\/span><span style=\"color: #ABB2BF\">         | Memory Foam Pillow<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This standardization improves data consistency and readability, which is crucial for product displays, search functionality, and reporting.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"><strong style=\"background-color: rgb(69, 136, 216); color: rgb(241, 235, 218); font-size: calc(12px + 0.390625vw); font-weight: bold;\">SQL Propercase with a Rapid Database Builder<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When working with SQL, executing efficient queries is straightforward, but sometimes more complex operations, like handling proper casing of text data, require extra attention.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is where rapid database builders like Five come into play. Five provides a MySQL database for your application and generates an automatic UI, making it easier to interact with and manage your data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Five allows you to create interactive forms, tables, dynamic charts, comprehensive PDF reports, and dashboards that are automatically generated based on your database schema. This makes it easier to visualize and analyze the results of queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Additionally, Five lets you write custom JavaScript and TypeScript functions, providing the flexibility to implement custom business logic that can interact with your data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once your application is ready, Five makes deployment easy with just a few clicks, allowing you to deploy your MySQL-based application to a secure, scalable cloud infrastructure. This lets you focus on developing, while Five handles the complexities of cloud deployment and infrastructure management.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re serious about using SQL efficiently, give Five a try.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/preview-php85.dzine.org\/five\/get-started\/\">Sign up for free access to Five\u2019s online development environment and start building your MySQL web application today.<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Propercase in Different SQL Dialects<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The implementations we&#8217;ve discussed so far are specific to SQL Server. Let&#8217;s look at how to achieve <code>propercase<\/code> in other popular SQL dialects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">MySQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL doesn&#8217;t have a built-in propercase function, but we can create one using a combination of string functions:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>DELIMITER \/\/\n\nCREATE FUNCTION ProperCase(str VARCHAR(255)) RETURNS VARCHAR(255)\nBEGIN\n  DECLARE c CHAR(1);\n  DECLARE s VARCHAR(255);\n  DECLARE i INT DEFAULT 1;\n  DECLARE bool INT DEFAULT 1;\n  DECLARE punct CHAR(17) DEFAULT ' ()[]{},.-_!@;:?\/';\n  SET s = LCASE( str );\n  WHILE i &lt; LENGTH( str ) DO\n    SET c = SUBSTRING( s, i, 1 );\n    IF LOCATE( c, punct ) > 0 THEN\n      SET bool = 1;\n    ELSEIF bool=1 THEN\n      IF c >= 'a' AND c &lt;= 'z' THEN\n        SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1));\n        SET bool = 0;\n      ELSEIF c >= '0' AND c &lt;= '9' THEN\n        SET bool = 0;\n      END IF;\n    END IF;\n    SET i = i+1;\n  END WHILE;\n  RETURN s;\nEND;\n\/\/\n\nDELIMITER ;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ABB2BF\">DELIMITER \/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">CREATE<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">FUNCTION<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #61AFEF\">ProperCase<\/span><span style=\"color: #ABB2BF\">(str <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">255<\/span><span style=\"color: #ABB2BF\">)) <\/span><span style=\"color: #C678DD\">RETURNS<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">255<\/span><span style=\"color: #ABB2BF\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">BEGIN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> c <\/span><span style=\"color: #C678DD\">CHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> s <\/span><span style=\"color: #C678DD\">VARCHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">255<\/span><span style=\"color: #ABB2BF\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> i <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> bool <\/span><span style=\"color: #C678DD\">INT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">DECLARE<\/span><span style=\"color: #ABB2BF\"> punct <\/span><span style=\"color: #C678DD\">CHAR<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #D19A66\">17<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">DEFAULT<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39; ()[]{},.-_!@;:?\/&#39;<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> s <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> LCASE( str );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">WHILE<\/span><span style=\"color: #ABB2BF\"> i <\/span><span style=\"color: #56B6C2\">&lt;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">LENGTH<\/span><span style=\"color: #ABB2BF\">( str ) DO<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> c <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">SUBSTRING<\/span><span style=\"color: #ABB2BF\">( s, i, <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\"> );<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">IF<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">LOCATE<\/span><span style=\"color: #ABB2BF\">( c, punct ) <\/span><span style=\"color: #56B6C2\">&gt;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> bool <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    ELSEIF bool<\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #C678DD\">IF<\/span><span style=\"color: #ABB2BF\"> c <\/span><span style=\"color: #56B6C2\">&gt;=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;a&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AND<\/span><span style=\"color: #ABB2BF\"> c <\/span><span style=\"color: #56B6C2\">&lt;=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;z&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> s <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #56B6C2\">CONCAT<\/span><span style=\"color: #ABB2BF\">(<\/span><span style=\"color: #56B6C2\">LEFT<\/span><span style=\"color: #ABB2BF\">(s,i-<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">),UCASE(c),<\/span><span style=\"color: #56B6C2\">SUBSTRING<\/span><span style=\"color: #ABB2BF\">(s,i+<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">));<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> bool <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      ELSEIF c <\/span><span style=\"color: #56B6C2\">&gt;=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;0&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">AND<\/span><span style=\"color: #ABB2BF\"> c <\/span><span style=\"color: #56B6C2\">&lt;=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #98C379\">&#39;9&#39;<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">THEN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">        <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> bool <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #D19A66\">0<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">      <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">IF<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">IF<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">    <\/span><span style=\"color: #C678DD\">SET<\/span><span style=\"color: #ABB2BF\"> i <\/span><span style=\"color: #56B6C2\">=<\/span><span style=\"color: #ABB2BF\"> i+<\/span><span style=\"color: #D19A66\">1<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\"> <\/span><span style=\"color: #C678DD\">WHILE<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">  <\/span><span style=\"color: #C678DD\">RETURN<\/span><span style=\"color: #ABB2BF\"> s;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C678DD\">END<\/span><span style=\"color: #ABB2BF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">\/\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #ABB2BF\">DELIMITER ;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can then use this function like so:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>SELECT ProperCase('the QUICK brown FOX') AS propercase_text;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> ProperCase(<\/span><span style=\"color: #98C379\">&#39;the QUICK brown FOX&#39;<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> propercase_text;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">PostgreSQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL offers the <code>initcap<\/code> function, which provides basic <code>propercase<\/code> functionality:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#abb2bf;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#abb2bf;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>SELECT initcap('the quick brown fox') AS propercase_text;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki one-dark-pro\" style=\"background-color: #282c34\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C678DD\">SELECT<\/span><span style=\"color: #ABB2BF\"> initcap(<\/span><span style=\"color: #98C379\">&#39;the quick brown fox&#39;<\/span><span style=\"color: #ABB2BF\">) <\/span><span style=\"color: #C678DD\">AS<\/span><span style=\"color: #ABB2BF\"> propercase_text;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">However, <code>initcap<\/code> doesn&#8217;t handle exceptions for words that should remain lowercase. For more control, you can create a custom function similar to our SQL Server example.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Performance Considerations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When working with large datasets, the performance of string manipulation functions can become a concern. Here are some tips to optimize <code>propercase<\/code> operations:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Indexing<\/strong>: If you frequently search or sort on the propercase column, consider creating a computed column with the propercase value and index it.<\/li>\n\n\n\n<li><strong>Caching<\/strong>: For static data, consider storing the propercase version rather than computing it on-the-fly.<\/li>\n\n\n\n<li><strong>Batch Processing<\/strong>: For large updates, process the data in batches to avoid long-running transactions.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Propercase in Application Logic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">While implementing <code>propercase<\/code> in SQL can be useful, it&#8217;s often more efficient to handle this in your application logic. Most programming languages have built-in or easily implementable propercase functions. Consider this approach if you&#8217;re dealing with large volumes of data or complex <code>propercase<\/code> rules.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Propercase, while seemingly simple, can be a useful tool for data standardization and presentation. By implementing <code>propercase<\/code> in SQL, you can ensure consistency directly at the database level. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The techniques we&#8217;ve explored here &#8211; from basic implementations to handling exceptions and applying in real-world scenarios &#8211; provide a solid foundation for working with <code>propercase<\/code> in SQL. As you apply these concepts, you&#8217;ll find numerous opportunities to improve data quality and presentation in your database projects.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<ol class=\"rank-math-list \">\n<li id=\"faq-question-1771985858796\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong>What is \u201cpropercase\u201d in SQL?<\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Propercase (or title case) is a text formatting style where <strong>the first letter of each word is capitalized and all other letters are lowercase<\/strong>, e.g., \u201cthe quick brown fox\u201d becomes \u201cThe Quick Brown Fox\u201d. Because most SQL dialects don\u2019t have a built\u2011in propercase function, you need to implement it manually in queries or via a function.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771985909936\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong><strong>How do you implement a basic propercase conversion in SQL?<\/strong><\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A simple approach is to take the first letter of a word, convert it to uppercase, then convert the rest to lowercase using functions like <code>UPPER()<\/code> and <code>LOWER()<\/code>, and then concatenate them back together.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771985985770\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong>Can SQL properly handle multi\u2011word strings for title case?<\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, with more advanced logic. For example, a user\u2011defined function (UDF) can loop through each character, capitalize the first letter of each word, and lowercase the rest. This lets you format multi\u2011word strings into proper case even without native SQL support.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771985994514\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong>How can exceptions (like \u201ca\u201d, \u201can\u201d, \u201cthe\u201d) be handled in propercase?<\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can customize your propercase function to include <strong>an exception list<\/strong>. Words in the list remain lowercase unless they appear at the beginning of the input string, enabling more nuanced title case formatting.<\/p>\n\n<\/div>\n<\/li>\n<li id=\"faq-question-1771986003404\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong><strong><strong><strong>Does propercase work differently in other SQL dialects?<\/strong><\/strong><\/strong><\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes. Some SQL dialects, like <strong>PostgreSQL<\/strong>, have functions like <code>initcap()<\/code> to convert text to proper case. Others, like <strong>MySQL<\/strong>, still require custom functions combining loops and string manipulation. Because of these differences, implementation varies by database engine.<\/p>\n\n<\/div>\n<\/li>\n<\/ol>\n<\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>propercase, also known as title case, is a text formatting style where the first letter of each word is capitalized. While it might seem like a simple concept, implementing propercase in SQL can be tricky due to the lack of a built-in function in most database systems. This article will guide you through various methods [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":4155,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[21],"tags":[],"class_list":["post-4153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide.jpg",1280,720,false],"thumbnail":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide-150x150.jpg",150,150,true],"medium":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide-300x169.jpg",300,169,true],"medium_large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide-768x432.jpg",768,432,true],"large":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide.jpg",1280,720,false],"2048x2048":["https:\/\/preview-php85.dzine.org\/five\/wp-content\/uploads\/2024\/09\/Five.Co-Propercase-in-SQL-Practical-Guide.jpg",1280,720,false]},"uagb_author_info":{"display_name":"Ryan Forrester","author_link":"https:\/\/preview-php85.dzine.org\/five\/author\/f1v5_ed9_au\/"},"uagb_comment_info":0,"uagb_excerpt":"propercase, also known as title case, is a text formatting style where the first letter of each word is capitalized. While it might seem like a simple concept, implementing propercase in SQL can be tricky due to the lack of a built-in function in most database systems. This article will guide you through various methods&hellip;","_links":{"self":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/4153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/comments?post=4153"}],"version-history":[{"count":1,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/4153\/revisions"}],"predecessor-version":[{"id":17810,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/posts\/4153\/revisions\/17810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media\/4155"}],"wp:attachment":[{"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/media?parent=4153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/categories?post=4153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/preview-php85.dzine.org\/five\/wp-json\/wp\/v2\/tags?post=4153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}