?
Solved

MS SQL 2000 Replace NULL is results

Posted on 2008-10-23
4
Medium Priority
?
212 Views
Last Modified: 2012-08-13
I have a view in MS SQL 2000 which is working and showing results.  There is one issue though, if there is no value for dbo.tblLeavers.fldHeadCount it shows as NULL in the results.  Can I replace this with a 0 in the SELECT statment.

SELECT     TOP 100 PERCENT dbo.tblHeadCount.fldCostCentre, dbo.tblHeadCount.fldDate, dbo.tblHeadCount.fldHeadCount,
                      dbo.tblLeavers.fldHeadCount AS fldLeavers
FROM         dbo.tblHeadCount LEFT OUTER JOIN
                      dbo.tblLeavers ON dbo.tblHeadCount.fldCostCentre = dbo.tblLeavers.fldCostCentre AND dbo.tblHeadCount.fldDate = dbo.tblLeavers.fldDate
WHERE     (LEN(dbo.tblHeadCount.fldCostCentre) > 1)
ORDER BY dbo.tblHeadCount.fldDate DESC
0
Comment
Question by:iepaul
[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
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 22784218
yes, using ISNULL()
SELECT     TOP 100 PERCENT dbo.tblHeadCount.fldCostCentre, dbo.tblHeadCount.fldDate, dbo.tblHeadCount.fldHeadCount, 
                      ISNULL(dbo.tblLeavers.fldHeadCount,0) AS fldLeavers
FROM         dbo.tblHeadCount LEFT OUTER JOIN
                      dbo.tblLeavers ON dbo.tblHeadCount.fldCostCentre = dbo.tblLeavers.fldCostCentre AND dbo.tblHeadCount.fldDate = dbo.tblLeavers.fldDate
WHERE     (LEN(dbo.tblHeadCount.fldCostCentre) > 1)
ORDER BY dbo.tblHeadCount.fldDate DESC

Open in new window

0
 
LVL 6

Expert Comment

by:openshac
ID: 22784221

ISNULL( dbo.tblLeavers.fldHeadCount, 0) AS fldLeavers

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22784225
side note: try to use table alias names:
SELECT     TOP 100 PERCENT hc.fldCostCentre, hc.fldDate, hc.fldHeadCount, isnull(l.fldHeadCount,0) AS fldLeavers
FROM         dbo.tblHeadCount hc 
LEFT OUTER JOIN dbo.tblLeavers l
  ON hc.fldCostCentre = l.fldCostCentre 
 AND hc.fldDate = l.fldDate
WHERE     (LEN(hc.fldCostCentre) > 1)
ORDER BY hc.fldDate DESC

Open in new window

0
 

Author Closing Comment

by:iepaul
ID: 31509128
Thanks for the help and the tip on using table alias
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

764 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