troubleshooting Question

How to include "NULL-fields" in SQL sum

Avatar of AGION
AGION asked on
Microsoft SQL Server 2005
3 Comments1 Solution449 ViewsLast Modified:
Hello experts,

I have a question about counting different fields where a couple of fields can be "NULL" in the database. I added the query as code. If some of these fields are NULL in the database it doesn't give a value of the rest of the fields.

I think the fields should be casted or converted by some sort of code to translate NULL into "0".

I hope someone can tell me how to change my query so it will work. If there are any questions, just ask!

Thanks in advance!
DECLARE @Vries AS numeric(19,6) 		
DECLARE @Over AS numeric(19,6)
DECLARE @Sorteren AS numeric(19,6)
DECLARE @Paneren AS numeric(19,6)
DECLARE @Inpak AS numeric(19,6)
DECLARE @Klop AS numeric(19,6)
DECLARE @Uitpak AS numeric(19,6)
DECLARE @Zaag AS numeric(19,6)
DECLARE @Voorbak AS numeric(19,6)
DECLARE @Vorm AS numeric(19,6)
DECLARE @Klein AS numeric(19,6)
DECLARE @Overig AS numeric(19,6)
DECLARE @Handling AS numeric(19,6)
DECLARE @Invoer AS numeric(19,6)
DECLARE @Inslag AS numeric(19,6)
DECLARE @Artikel AS varchar(32)
 
 
SET @Artikel = (SELECT $[$38.1.0])
 
SET @Vries = (SELECT U_Vries FROM OITM WHERE ItemCode = @Artikel)
SET @Over = (SELECT U_Over FROM OITM WHERE ItemCode = @Artikel)
SET @Sorteren = (SELECT U_Sorteren FROM OITM WHERE ItemCode = @Artikel)
SET @Paneren = (SELECT U_Paneren FROM OITM WHERE ItemCode = @Artikel)
SET @Inpak = (SELECT U_Inpak FROM OITM WHERE ItemCode = @Artikel)
SET @Klop = (SELECT U_Klop FROM OITM WHERE ItemCode = @Artikel)
SET @Uitpak = (SELECT U_Uitpak FROM OITM WHERE ItemCode = @Artikel)
SET @Zaag = (SELECT U_Zaag FROM OITM WHERE ItemCode = @Artikel)
SET @Voorbak = (SELECT U_Voorbak FROM OITM WHERE ItemCode = @Artikel)
SET @Vorm = (SELECT U_Vorm FROM OITM WHERE ItemCode = @Artikel)
SET @Klein = (SELECT U_Klein FROM OITM WHERE ItemCode = @Artikel)
SET @Overig = (SELECT U_Overig FROM OITM WHERE ItemCode = @Artikel)
 
SELECT @Vries + @Over + @Sorteren + @Paneren + @Inpak + @Klop + @Uitpak + @Zaag + @Voorbak + @Vorm + @Klein + @Overig
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros