Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsBig 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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: Raynard7Posted on 2007-02-14 at 14:18:53ID: 18536158
Comments are available to members only. Sign up or Log in to view these comments.