Solved

Subquery needs 0 instead of null

Posted on 2013-01-24
2
349 Views
Last Modified: 2013-01-24
I have the following sql with a subquery.  If the subquery does not return a record I need it to return a 0. Tried to figure out something with isnull()

SELECT
            ClientId,

             (SELECT  SUM(ClientDebtXref.Balance)  FROM ClientDebtXref WHERE ClientDebtXref.ClientApplicationID = @ClientID AND DebtTypeID=7 )  HomeEquityBalance,


               CurrentMonthlyOutstandingMortagageBalance ,
             AssetLienBalance
from Assets
0
Comment
Question by:charlesbaldo
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 38816924
try this

SELECT
            ClientId,

            isnull( (SELECT  SUM(ClientDebtXref.Balance)  FROM ClientDebtXref WHERE ClientDebtXref.ClientApplicationID = @ClientID AND DebtTypeID=7 ) ,0)  HomeEquityBalance,


               CurrentMonthlyOutstandingMortagageBalance ,
             AssetLienBalance
from Assets 

Open in new window

0
 

Author Closing Comment

by:charlesbaldo
ID: 38816929
Thanks it works
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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