Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Nov 30, 1999

Values Resulting to Null

Question:
I want to add two numeric fields with values like these:

Example 1: One field named Amount contains 565.25 and other field named Ticket contains null.

 
select amount + ticket 
The result fetched is null. But the result should be 565.25 instead of null.

Example 2:

 
Select 565.25 + null
Results to null as well. How can I fix this ?

Answer:
As you have discovered, the result of any operation where an operand is null is NULL!

This is overcome by taking a little extra care in your table create statement. What is required is provision for a default value against a column that is not allowed to be null. In your case, you need a default value of 0 (zero) so that you can derive the sums you envision. This will not work if one of the parties to the operation is null.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date