[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

02/14/2007 at 02:12PM PST, ID: 22389992
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Join issue - Return all rows for Table A and if amount table B, return row, else return null/0 field

Asked by LFreehauf in SQL Server 2005

Tags: rows, all, return, join, table

Big Picture – For a given month, if a tenant has an amount posted to the CamCharge table, I want to return the tenant and the charge amount (done with that tenant).  If other tenants do not have an amount posted the to CamCharge table, I want to see the Tenant, but with a zero or null for charge amount.   The following select statement works, except it returns two rows for tenants with a corresponding row in CamCharge table (i.e. $100) and a second row with a $0.  

Here is my SQL Statement

Select  distinct p.sCode
, tenant.sCode
, camcharg.dtmmyy as date
, isnull(chargtyp.sCode, 's-act')  as charge
, camcharg.dexpense as expense
From  Tenant join Property P ON  p.hMy = tenant.hProperty  
Left Outer Join camcharg ON tenant.hMyPerson = camcharg.hTenant  
and camcharg.dtmmyy = '1/1/2006'
left outer Join chargtyp ON chargtyp.hMy = camcharg.hChargeCode  
and chargtyp.scode = 's-act'
Where
p.scode = '4corner'
order by tenant.scode


Objective:  
1.      Works: Return all rows from the “tenant” table with camcharg.dtmmyy = '1/1/2006' and chargtyp.scode  's-act'
2.      Works: If the “Camcharg” table does not have corresponding record (indicating no charges applied for ‘1/1/2006’ date range) then return $0 for camcharg.dExpense


P.Scode      T.scode       date      charge      camcharge.dexpense
4corner      TenantA      1/1/2006      s-act      $0                   <----Problem (extra row)
4corner      TenantA      1/1/2006      s-act      $100.       
4corner      TenantB      1/1/2006      s-act      $0      
4corner      TenantC      1/1/2006      s-act      $0
            

TenantA is the problem:  The select statement returns an extra row if the Tenant has a corresponding row in the CamCharge table.  If Tenant (i.e. Tenant A) has a corresponding row in Camcharge (i.e. dExpense= $100) then return only that row.  Don’t return two rows (row one $0 and row 2 with the $100)

Thanks again
[+][-]02/14/07 02:18 PM, ID: 18536158

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: rows, all, return, join, table
Sign Up Now!
Solution Provided By: Raynard7
Participating Experts: 4
Solution Grade: A
 
 
[+][-]02/14/07 02:19 PM, ID: 18536163

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/14/07 02:21 PM, ID: 18536170

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/07 11:28 AM, ID: 20256734

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91