Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Null Field with a numerical field 1

Status
Not open for further replies.
Dec 5, 2001
82
0
0
GB
Hello,

There is probably a simple answer to this question. I'm trying to write a view but I've got a field which is null and I wish to add it to a numerical field. I've create the view and there is something in FIN2 but FIN1 is null so when I add FIN1 and FIN2 the total field is blank:

Claim FIN1 FIN2 Total
0111011 1200

I would like to effective do the followig in SQL

set FIN1 if null to 0 then add FIN1 to FIN2:

Claim FIN1 FIN2 Total
011101 0 1200 1200

Can this be done and what is the syntax?

Oracle 7.3
SQL Worksheet 1.3.6

Thanks [2thumbsup]
 
Solved it.

used the nvl function

nvl(fin1,0) replaces the fin1 field with 0 if it is null

nvl(fin1,0)+fin2 = 1200

[bigsmile]
 
Just use the nvl (null value) function eg

nvl(fin1,0)

This would treat any null in the field fin1 as 0

This could be used like this:-

select nvl(fin1,0), nvl(fin2,0), nvl(fin1,0) + nvl(fin2,0) as total from mytable;

to give:-
fin1 fin2 total
0 1200 1200

etc.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top