Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Self-join field addition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephanie - 03 Nov 2005 19:11 GMT
Hi.  I'm frustrated!  I can't figure out why this won't work.  Must be user
error!  Here's the setup: both Contacts and SignificantOthers (these spouses
are themselves Contacts, hence the self join) can earn, use and lose bucks.
Ultimately, I'm trying to calculate how many bucks are avialable from Contact
and Spouse together.  Here's what I have:
[BucksEarned]+[BucksUsed]+[BucksLost]=BucksAvailable   and this part works.

[SpouseBucksEarned]+[SpouseBucksUsed]+[SpouseBucksLost]=SpouseBucksAvailabe  
does NOT work. Say I have 18-3-4=11  then SpouseBucksAvailable should be 11.

However, rather than adding together, all 3 numbers show up in one query
column: 18-3-4
I want to be able to add this SpouseBucksAvailable column (that should be
11) to the BucksAvailable column to get a total.  (really, these 3 step
queries kill me!)

Here's my query- I'd appreciate suggestions.  Thanks.

SELECT AllBucksByContactSumTotal.ContactID,
AllBucksByContactSumTotal.BucksEarned AS BucksEarned,
AllBucksByContactSumTotal.BucksUsed AS BucksUsed,
AllBucksByContactSumTotal.BucksLost AS BucksLost,
[BucksEarned]+[BucksUsed]+[BucksLost] AS BucksAvailable,
AllBucksByContactSumTotal.SignificantOtherID,
nz([AllBucksBySpouse].[BucksEarned],0) AS SpouseBucksEarned,
nz([AllBucksBySpouse].[BucksUsed],0) AS SpouseBucksUsed,
nz([AllBucksBySpouse].[BucksLost],0) AS SpouseBucksLost
FROM AllBucksByContactSumTotal LEFT JOIN AllBucksByContactSumTotal AS
AllBucksBySpouse ON AllBucksByContactSumTotal.SignificantOtherID =
AllBucksBySpouse.ContactID
WHERE (((AllBucksByContactSumTotal.SignificantOtherID)<>0) AND
((AllBucksByContactSumTotal.PrimaryFamilyMember)=True)) OR
(((AllBucksByContactSumTotal.SignificantOtherID)=0));
John Spencer - 03 Nov 2005 20:26 GMT
Evidently, your spousebucks fields are being treated as text strings vice
numbers.  The culprit is probably the NZ function.  Try Wrapping the NZ()
inside of CCUR.

CCUR(nz([AllBucksBySpouse].[BucksEarned],0)) AS SpouseBucksEarned

Repeat on the other columns (fields).

> Hi.  I'm frustrated!  I can't figure out why this won't work.  Must be
> user
[quoted text clipped - 35 lines]
> ((AllBucksByContactSumTotal.PrimaryFamilyMember)=True)) OR
> (((AllBucksByContactSumTotal.SignificantOtherID)=0));
Stephanie - 03 Nov 2005 21:00 GMT
You are fabulous!  That did the trick. Thanks for the help.

> Evidently, your spousebucks fields are being treated as text strings vice
> numbers.  The culprit is probably the NZ function.  Try Wrapping the NZ()
[quoted text clipped - 43 lines]
> > ((AllBucksByContactSumTotal.PrimaryFamilyMember)=True)) OR
> > (((AllBucksByContactSumTotal.SignificantOtherID)=0));
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.