{"id":26443,"date":"2023-06-01T07:14:00","date_gmt":"2023-06-01T05:14:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=26443"},"modified":"2023-07-29T18:19:18","modified_gmt":"2023-07-29T16:19:18","slug":"sql-server-case-statement","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/","title":{"rendered":"SQL Server CASE Statement with code examples"},"content":{"rendered":"\n<p>The SQL Server CASE statement is a conditional operation that can be used to provide if-then-else type of logic to T-SQL queries. The CASE statement can be used in SQL Server queries involving calculations, data transformation, and more.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-overview-of-the-case-statement-in-sql-server\">1. Overview of the CASE Statement in SQL Server<\/h2>\n\n\n\n<p>The CASE operator in SQL Server is a powerful tool for creating more complex queries, particularly when you want to return different results based on conditions. The CASE statement works like an if-then-else block in other programming languages, allowing you to test conditions and return different results based on those conditions. Indeed, the generic syntax of a CASE statement in T-SQL is represented like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CASE \n   WHEN condition1 THEN result1 \n   WHEN condition2 THEN result2 \n   ...\n   ELSE default_result \nEND\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-create-the-sample-table\"><em>Create the Sample Table<\/em><\/h3>\n\n\n\n<p>For our examples, let&#8217;s create a table <code>Orders<\/code> and populate it with some data, i.e., 7 lines with different order statuses.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Create the Orders table\nCREATE TABLE [dbo].[Orders](\n    [OrderID] [int] PRIMARY KEY,\n    [CustomerID] [int] NOT NULL,\n    [OrderAmount] [decimal](10,2) NOT NULL,\n    [OrderStatus] [nvarchar](20) NOT NULL\n);\n\n-- Insert data into the Orders table\nINSERT [dbo].[Orders] VALUES (1, 1, 100.00, 'Processed');\nINSERT [dbo].[Orders] VALUES (2, 2, 200.00, 'Shipped');\nINSERT [dbo].[Orders] VALUES (3, 1, 300.00, 'Returned');\nINSERT [dbo].[Orders] VALUES (4, 3, 150.00, 'Shipped');\nINSERT [dbo].[Orders] VALUES (5, 4, 250.00, 'Processed');\nINSERT [dbo].[Orders] VALUES (6, 2, 350.00, 'Returned');\nINSERT [dbo].[Orders] VALUES (7, 1, 400.00, 'Shipped');\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-using-the-case-statement-in-a-select-query\">2. Using the CASE Statement in a SELECT query<\/h2>\n\n\n\n<p>We can use a CASE query in T-SQL within the SELECT clause to change how the data is displayed based on conditions. For example, we can add a new column to our query that shows if the <code>OrderAmount<\/code> is &#8216;High&#8217; or &#8216;Low&#8217;:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT OrderID, \n       CustomerID, \n       OrderAmount,\n       OrderStatus,\n       CASE \n           WHEN OrderAmount > 300 THEN 'High'\n           ELSE 'Low'\n       END AS OrderValue\nFROM Orders;\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-case-statement-and-where-clause\">3. CASE Statement and WHERE Clause<\/h2>\n\n\n\n<p>We can use a SQL Server CASE statement in the WHERE section to dynamically filter records. For example, we can filter orders based on their status and amount:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT OrderID, \n       CustomerID, \n       OrderAmount,\n       OrderStatus\nFROM Orders\nWHERE (CASE \n           WHEN OrderStatus = 'Processed' AND OrderAmount > 200 THEN 1\n           WHEN OrderStatus = 'Shipped' AND OrderAmount &lt; 200 THEN 1\n           ELSE 0\n       END) = 1;\n<\/pre>\n\n\n\n<p>This query will return the orders that are either &#8216;Processed&#8217; with an amount greater than 200 or &#8216;Shipped&#8217; with an amount less than 200. On the same topic, here is <a href=\"https:\/\/expert-only.com\/en\/t-sql\/comparison-operators-in-t-sql\/\"><strong>how to compare data with SQL Server<\/strong><\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"8ixI235sJO\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/comparison-operators-in-t-sql\/\">How to Compare Values in T-SQL?<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to Compare Values in T-SQL?&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/comparison-operators-in-t-sql\/embed\/#?secret=bKj5oRYXEO#?secret=8ixI235sJO\" data-secret=\"8ixI235sJO\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Using the CASE keyword with Aggregate Functions<\/h2>\n\n\n\n<p>In this example, we will use the T-SQL CASE query with aggregate functions like SUM and COUNT to group orders based on certain predefined and selected conditions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT CustomerID,\n       COUNT(OrderID) AS TotalOrders,\n       SUM(CASE \n               WHEN OrderStatus = 'Processed' THEN 1\n               ELSE 0\n           END) AS ProcessedOrders,\n       SUM(CASE \n               WHEN OrderStatus = 'Shipped' THEN 1\n               ELSE 0\n           END) AS ShippedOrders,\n       SUM(CASE \n               WHEN OrderStatus = 'Returned' THEN 1\n               ELSE 0\n           END) AS ReturnedOrders\nFROM Orders\nGROUP BY CustomerID;\n<\/pre>\n\n\n\n<p>This query will return the total number of orders for each customer, as well as the number of orders in each status (Processed, Shipped, Returned).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. SQL Server CASE Statement with ORDER BY<\/h2>\n\n\n\n<p>We can use the CASE statement in the ORDER BY clause to sort records based on certain conditions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT OrderID, \n       CustomerID, \n       OrderAmount,\n       OrderStatus\nFROM Orders\nORDER BY \n    CASE \n        WHEN OrderStatus = 'Processed' THEN 1\n        WHEN OrderStatus = 'Shipped' THEN 2\n        WHEN OrderStatus = 'Returned' THEN 3\n        ELSE 4\n    END;\n<\/pre>\n\n\n\n<p>This query will sort the orders by their status, with &#8216;Processed&#8217; orders first, followed by &#8216;Shipped&#8217;, then &#8216;Returned&#8217;, and finally any other status.<\/p>\n\n\n\n<p>These examples showcase the <a href=\"https:\/\/www.sciencedirect.com\/topics\/computer-science\/switch-case-statement\" target=\"_blank\" rel=\"noreferrer noopener\">flexibility and power of the CASE statement<\/a> in SQL Server, and how it can be used in various parts of a query to add conditional logic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-conclusion-on-the-t-sql-case-statement\">Conclusion on the T-SQL CASE statement <\/h3>\n\n\n\n<p>To conclude, the CASE statement is an incredibly powerful and flexible tool in SQL Server, enabling dynamic and conditionally evaluated SQL expressions. Whether it&#8217;s used in SELECT, UPDATE, DELETE, or INSERT statements, or within a WHERE clause, the CASE statement adds substantial versatility to your SQL syntax. It essentially allows us to create different paths and outcomes in our SQL statements based on specific conditions. However, mastering it requires practice and understanding of its syntax and possible use cases.<\/p>\n\n\n\n<p>By continuously experimenting with and implementing the CASE statement in various scenarios, you can enhance the effectiveness and efficiency of your SQL queries, making your data manipulation tasks more streamlined and readable. Remember, good SQL development is not just about getting the right results, but also about making your code understandable and maintainable, also by other developers.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>The SQL Server CASE statement is a conditional operation that can be used to provide if-then-else type of logic to T-SQL queries. The CASE statement can be used in SQL Server queries involving calculations, data transformation, and more. 1. <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\" title=\"SQL Server CASE Statement with code examples\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":10669,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-26443","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server CASE Statement with code examples - T-SQL<\/title>\n<meta name=\"description\" content=\"The SQL Server CASE statement is a conditional statement used to provide if-then-else type of logic to T-SQL queries.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server CASE Statement with code examples\" \/>\n<meta property=\"og:description\" content=\"The SQL Server CASE statement is a conditional statement used to provide if-then-else type of logic to T-SQL queries.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-01T05:14:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-29T16:19:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"SQL Server CASE Statement with code examples\",\"datePublished\":\"2023-06-01T05:14:00+00:00\",\"dateModified\":\"2023-07-29T16:19:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\"},\"wordCount\":546,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\",\"name\":\"SQL Server CASE Statement with code examples - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg\",\"datePublished\":\"2023-06-01T05:14:00+00:00\",\"dateModified\":\"2023-07-29T16:19:18+00:00\",\"description\":\"The SQL Server CASE statement is a conditional statement used to provide if-then-else type of logic to T-SQL queries.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server CASE Statement with code examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server CASE Statement with code examples - T-SQL","description":"The SQL Server CASE statement is a conditional statement used to provide if-then-else type of logic to T-SQL queries.","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:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server CASE Statement with code examples","og_description":"The SQL Server CASE statement is a conditional statement used to provide if-then-else type of logic to T-SQL queries.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2023-06-01T05:14:00+00:00","article_modified_time":"2023-07-29T16:19:18+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"SQL Server CASE Statement with code examples","datePublished":"2023-06-01T05:14:00+00:00","dateModified":"2023-07-29T16:19:18+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/"},"wordCount":546,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/","url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/","name":"SQL Server CASE Statement with code examples - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg","datePublished":"2023-06-01T05:14:00+00:00","dateModified":"2023-07-29T16:19:18+00:00","description":"The SQL Server CASE statement is a conditional statement used to provide if-then-else type of logic to T-SQL queries.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/heavy-antique-typewriter-4DCBC2BD36D_1920x1080-2.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-case-statement\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"SQL Server CASE Statement with code examples"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/26443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=26443"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/26443\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/10669"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=26443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=26443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=26443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}