SQL Server - Count Distinct or similar function

Asked By Elvin Pena on 17-Mar-13 11:05 PM
Hello, I am using SQL server mgmt studio 2008 r2 and I have a situation where I joined two views to get just one field where it is calculation based on conditions. 
I have the following sample SQL statement where I get red squiggly syntax error underlined to get the field from the other view: 

In the select, I got this:
Isnull((CASE WHEN bsd.StatusID= 01 AND bsd.TypeID = 10 THEN  bsd.Amt * bsd.Qty ELSE  0 END ),0) as TotalLineItemAmt,

In the from statement, I got this:
INNER JOIN dbBillsAndInvoices..StatementDetails bsd ON bsd.StatementID = b.StatementID

The view, which is the using the inner join above, returns 49 rows which I know for sure the StatementDetails table returns 9 rows that are confirmed as true known fact. 

How would I make the statement above define only 9 rows and not 49 rows using a similar Count Distinct or something valid?
Rohan Dave replied to Elvin Pena on 19-Mar-13 04:04 AM
try to use "Distinct" in your view itself..

and then check the result...