Solved

Subquery needs 0 instead of null

Posted on 2013-01-24
2
350 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

791 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