Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Subquery needs 0 instead of null

Posted on 2013-01-24
2
Medium Priority
?
360 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:Charles Baldo
2 Comments
 
LVL 39

Accepted Solution

by:
appari earned 2000 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:Charles Baldo
ID: 38816929
Thanks it works
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

972 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