Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Query to return default value if column contains null value in SQL Server

Jul 10, 2012
Introduction:

Here I will explain how to write a query to return default value if column contains null value in SQL Server.

Description:

In previous articles I explained how to delete null or empty values from datatable in SQL Server and many articles relating to SQL Server. Now I will explain how to write a query to return default if column contains null value in SQL Server. For that first design one table (UserInfo) in database and enter data like as shown below

UserId
Name
City
Education
1
Suresh
Guntur
B.Tech
2
Nagaraju
NULL
MCA
3
Sai
NULL
MBA
4
Madhav
NULL
MBBS
Query to return default values if column contains null value

If we want to return default value if column contains null value in SQL Server that would be like as shown below


SELECT UserId,Name,ISNULL(City,'Tenali'),Education FROM UserInfo
In above query I written condition if City column contains null value then it will return value as 'Tenali'

Output

UserId
Name
City
Education
1
Suresh
Guntur
B.Tech
2
Nagaraju
Tenali
MCA
3
Sai
Tenali
MBA
4
Madhav
Tenali
MBBS

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Sudha SG said...

Really thanks for all ur posts

Anonymous said...

thanks alot

Unknown said...

we can use COALESCE to replace null value.

Unknown said...

Thanks alot dear very usefull

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.