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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Performing Left Join

Status
Not open for further replies.

williey

Technical User
Jan 21, 2004
242
Hi,
I did a 2 table join. The Total column is the result of the sum of Column1 and Column2. When there is no match, either column1 or column2 will return empty. How do I get it to return 0? The example shows the Total column will be empty if either Column1 or Column2 is empty.


Code:
EmpNo	Reg Hours	Column1	      Column2	Total
01673	   536	          375		
02018	   518		                269	
02030	   544		                835	
02033	   472		                362	
04271	   526	          567		
04771	   404		                395	
04785	   504	          364		
04822	   504	          110		
04898	   548		               2899	
04971	   498		                135	
05058	   305	          519	  1000     1519

------------------------------------------
There are 10 kinds of people in this world. One that understands binary and the other one that does not.
 
Check out the NZ function. The empty columns are probably NULL and NULL + anything is NULL.
 
Have a look at the Nz function:
SELECT ..., Sum(Nz(Column1,0)+Nz(Column2,0)) AS Total, ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You could use the NZ() function.
Code:
nz([Column1], 0)

or Nz([Column1])

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Thanks guys for your help!

------------------------------------------
There are 10 kinds of people in this world. One that understands binary and the other one that does not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top