Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Linking Tables problem Post Reply Post New Topic
Author Message
PLTyler
Newbie
Newbie


Joined: 03 Jan 2009
Online Status: Offline
Posts: 24
Quote PLTyler Replybullet Topic: Linking Tables problem
     Posted: 03 Aug 2012 at 7:01am
Hi,

Using CR XI R2....

I have 2 linked tables. One in Access and the other in SQL Server 2008. The tables are linked by account number.

In Access there is a single record for the annual budget (by account number) and in SQL Server there are multiple transactions (by account number).

When I generate a report the Access 'budget' amount is multiplied by the number of transactions in the SQL Server 'transactions' table so the result is rubbish.

Is there a way to 'select distinct' on the Access budget table to prevent the multiplication of results in the Access budget table?

Thanks!

Edited by PLTyler - 03 Aug 2012 at 7:03am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 03 Aug 2012 at 7:42am

No.  If you are familiar with SQL, think about how queries pull data - you get every value for every field you have in your select statement, regardless of the table the value comes from.

 
However, there are a couple of ways around this.  For both of these you'll group on the Account number from the Access database.
 
1.  Use a Running Total field to sum the annual numbers that evaluates on change of Account Number.
 
2.  Create a formula that looks something like this:
 
If PreviousIsNull({access_table.account}) or {access_table.account} <> previous({access_table.account}) then {access_table.annual_budget} else 0
 
You should then be able to sum this formula.
 
-Dell
 
IP IP Logged
PLTyler
Newbie
Newbie


Joined: 03 Jan 2009
Online Status: Offline
Posts: 24
Quote PLTyler Replybullet Posted: 05 Aug 2012 at 11:22pm
Hi Dell,

Thanks so much for this information. The formula is very clever! I will try both options out and get back to you if there is a problem.

Thanks again.

Peter Tyler
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2012 at 3:48am

Sorry but you won't be able to sum the result as it uses the previous()function inthe formula.

as alternatives you can either use Dell's formula in a manual running total formulas (with shared variables) or you can use Crystal Running Totals to sum a value on usinng the on change of field ({access_table.account}) option


Edited by DBlank - 07 Aug 2012 at 4:26am
IP IP Logged
PLTyler
Newbie
Newbie


Joined: 03 Jan 2009
Online Status: Offline
Posts: 24
Quote PLTyler Replybullet Posted: 06 Aug 2012 at 7:18pm
Thanks for this.

Peter Tyler
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum