Solved

MS SQL 2000 Replace NULL is results

Posted on 2008-10-23
4
206 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
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

756 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