---
title: "SQL Rename NULL"  
description: "SQL Rename NULL"  
author: "Anonymous User"  
published: 2013-04-03  
updated: 2013-04-03  
canonical: https://www.mindstick.com/forum/704/sql-rename-null  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# SQL Rename NULL

Hi All!\
I searched and tried alot now, to [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out how to [replace](https://yourviews.mindstick.com/view/81330/cow-antibody-research-in-usa-a-step-ahead-to-replace-plasma-therapy) the name 'NULL' in a table, when I run this query:\
[SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) YEAR(orderdate) AS Years, (CASE WHEN [country](https://yourviews.mindstick.com/view/85543/do-you-think-that-french-will-be-islamic-country) = 'US' THEN 'US' ELSE 'WORLD' END) AS [region](https://www.mindstick.com/forum/158172/what-is-the-dholera-special-investment-region-in-gujarat), SUM(netamount) AS TotSalesFROM [orders](https://answers.mindstick.com/qa/43206/what-were-the-fundamental-orders-of-connecticut-and-who-wrote-them) o JOIN [customers](https://www.mindstick.com/articles/13008/how-does-a-customer-portal-enhance-the-experience-of-customers) c ON o.customerid = c.customeridGROUP BY (CASE WHEN country = 'US' THEN 'US' ELSE 'WORLD' END),YEAR(orderdate) WITH ROLLUP;I get this table: http://imgur.com/pzHa8fK\
I want to replace the Nulls to 'SubTotal' respectively 'GrandTotal'. I tried it with:\
[COALESCE](https://www.mindstick.com/forum/158915/explain-the-purpose-of-the-coalesce-function-in-sql-and-provide-an-example)(year(orderdate), 'Subtotal') years,...and the same with 'IFNULL(...)' but instead of replacing the name, it makes an extra [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) with years where all the years are listed again and the NULL's \
are still remaining.\
Any idea?\
[Advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) Thanks!

## Replies

### Reply by AVADHESH PATEL

Hi Tanuj!\
Try this way \
One way you can do this is to wrap your query in another select and then replace the null values with a COALESCE or a CASE expression:\
select case when Years is null and region is null then 'GrandTotal' when Years is null then 'SubTotal' else Years end Years, coalesce(region, '') region, TotSalesfrom( SELECT YEAR(orderdate) AS Years, (CASE WHEN country = 'US' THEN 'US' ELSE 'WORLD' END) AS region, SUM(netamount) AS TotSales FROM orders o JOIN customers c ON o.customerid = c.customerid GROUP BY (CASE WHEN country = 'US' THEN 'US' ELSE 'WORLD' END),YEAR(orderdate) WITH ROLLUP) \
I hope it resolve your problem\


---

Original Source: https://www.mindstick.com/forum/704/sql-rename-null

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
