Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to replace Null Values with a 0 in a stored procedure?

Posted on 2006-11-21
2
Medium Priority
?
541 Views
Last Modified: 2012-05-05
I have the following stored procedure that works fine. I would like to tidy up one thing - the 'Jan' column displays data and null values, I would like to replace the null values with 0. Can anyone tell me how to do this (I am using SQL Server 2005)?

ALTER PROCEDURE [dbo].[RollingAFR]
(
@Year INT
) AS
BEGIN
SELECT O.Region, O.Description, (SELECT (Sum([VSeverity].[CountOfSeverity])*100000)/Sum([VHours].[Total]) AS AFR
FROM [VHours] LEFT JOIN VSeverity ON ([VHours].Unit_Office = VSeverity.Unit_Office) AND ([VHours].Year = VSeverity.Year) AND ([VHours].Period = VSeverity.Period)
WHERE ((([VHours].Unit_Office)= O.Description) AND (([VHours].Year)=@Year) AND (([VHours].Period)<=1)) OR ((([VHours].Unit_Office)= O.Description) AND (([VHours].Year)=(@Year-1)) AND (([VHours].Period)>1))
) AS Jan
FROM dbo.tbl_RegionOffice AS O
END
RETURN
0
Comment
Question by:kenmck
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 304 total points
ID: 17986986
ALTER PROCEDURE [dbo].[RollingAFR]
(
@Year INT
) AS
BEGIN
SELECT O.Region, O.Description, coalesce((SELECT (Sum( coalesce([VSeverity].[CountOfSeverity],0) )*100000)/Sum([VHours].[Total]) AS AFR
FROM [VHours] LEFT JOIN VSeverity ON ([VHours].Unit_Office = VSeverity.Unit_Office) AND ([VHours].Year = VSeverity.Year) AND ([VHours].Period = VSeverity.Period)
WHERE ((([VHours].Unit_Office)= O.Description) AND (([VHours].Year)=@Year) AND (([VHours].Period)<=1)) OR ((([VHours].Unit_Office)= O.Description) AND (([VHours].Year)=(@Year-1)) AND (([VHours].Period)>1))
),0) AS Jan
FROM dbo.tbl_RegionOffice AS O
END
RETURN
0
 

Author Comment

by:kenmck
ID: 18018122
Thanks for that worked a treat.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question