Coalesce (add together multiple elements) are used in a Case statement in SQL Server. If the value in one of the columns is not available then use the value of the second column and if that is also not available, then use the third column. If none of the columns have the value, then null is returned for that value.
I've a table having the structure as depicted below:
I will apply on the Coalesce function on the Category table to fetch the information of three columns in a single column alias. It ignores null values of each column.
I have created a query to retrieve the desired information. Kindly see the depiction in the image below:
If you notice in the image shown above we have combined three columns (having null values also) together and get a single column Category.
Note: it doesn't fit in that condition, if you have columns having values (other than null) in a table and want to put them into a Coalesce function.
I've changed a structure a little bit and added one more column, Technology, into the Category table. Kindly see the Category table structure in an image shown below.
It returns the value of the first non-null column. I've also changed a query as well and added a “Technology” column with a Coalesce function.
Kindly refer to the image shown below.
It's very simple to learn and may be utilized in the future.
To learn more about MVC please go to the following link.
MVC Articles
Thanks.
Enjoy Coding and Reading.