Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-21
2
Medium Priority
?
538 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

705 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