Solved

Subquery needs 0 instead of null

Posted on 2013-01-24
2
346 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
Comment Utility
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
Comment Utility
Thanks it works
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now