Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Select expert condition Post Reply Post New Topic
Author Message
namitanamburi
Newbie
Newbie


Joined: 26 Mar 2009
Online Status: Offline
Posts: 39
Quote namitanamburi Replybullet Topic: Select expert condition
     Posted: 15 Jul 2009 at 8:59am
< ="Content-" content="text/; charset=utf-8">< name="ProgId" content="Word.">< name="Generator" content="Microsoft Word 10">< name="Originator" content="Microsoft Word 10"><>

Hello,

 

I have an issue and I would like to know how to handle this.

There are certain paymnets that are taken at bank and the transactions are like this

 

 

Date                 Tran#    AcctType  site # amount

 

10/12/2006          100       Sav           2      $120.00

 

10/12/2006          200       chk           3      $140.00

 

1/12/2007           156        sav            1       $128.00

 

 

Iam trying to retrieve all transaction for 10/12/2006.

 

The date is in table A

 

Tran# and Amount are in table B

 

Table C has two columns called Name and value which save all misc details like location type, account type and the site# etc.

 

Table C is like this.

 

Tran#   Name    Value

 

100   Acct_type   Chk

 

200   Acct_type   sav

 

100    site        2

 

100    site        3

 

and so on

 

 

In the select expert

 

I mentioned

 

Table A.date = {?enter_date} and

 

Table C.name in ["acct_type","site"]

The report design has the formula for acct type and site# as

 

{@acct_type}

 

is

 

If {table C.name} ="acct_type" then {table C.value}

 

{@site}

is

 

If {table C.name} ="site" then {table C.value}

 

when I enter date as 10/12/2006 the report preview is

 

 

Date           Tran#    AcctType   site#  amount

 

 

10/12/2006     100       Sav                       $120.00

 

10/12/2006                                     2      $120.00

 

10/12/2006      200      chk             3      $140.00

 

10/12/2006                                    3      $140.00

 

 

There are only two transactions. My expected result is

 

 

Date                 Tran#    acct Type  site # amount

 

10/12/2006          100       Sav         2      $120.00

 

10/12/2006          200       chk         3      $140.00

 

Basically the site # has to be beside the acct type instead of coming up as a new transaction.

 

Can you tell me if there are changes that need to be made in the select expert to retrieve the required result.

 

 

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 16 Jul 2009 at 6:34am
your report is displaying the data that SQL returns to it.  You are going to have a hard time getting rid of the extra row.  In Table C you have 2 entries for every 1 transaction, and since you need information from both lines, SQL HAS to return 2 lines, or you need to do something like:
 
select a.date, b.amount, c.value, d.value
from tableA as A
 join tableB as b on b.tran=a.tran
 join tableC as c on c.tran=a.tran
 join tableC as d on d.tran=a.tran
where c.name='Acct type' and d.name='site'
 
Not pretty, but that is the sort of join that you need.
 
HTH
IP IP Logged
namitanamburi
Newbie
Newbie


Joined: 26 Mar 2009
Online Status: Offline
Posts: 39
Quote namitanamburi Replybullet Posted: 17 Jul 2009 at 9:29am
Well,


I did try a query as you mentioned, basically joined table c twice


select statements twice and did a union yet I cudnt get the results, one record is displayed twice as before.

Anymore suggestions.


Nammu



IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Jul 2009 at 6:16am
i am not positive this will work, but you can try:
select a.date, b.amount, c.value, d.value
from tableA as A
 join tableB as b on b.tran=a.tran
 join tableC as c on c.tran=a.tran AND c.name='Acct type'
 join tableC as d on d.tran=a.tran and d.name='site'
this might reduce the number of records being associated, and give the one row that is desired.
 
Last thought:
select a.date, b.amount, c.value, d.value
from tableA as A
 join tableB as b on b.tran=a.tran
 join (select * from tableC Where name='Acct type') as c on c.tran=a.tran
 join (select * from tableC where d.name='site')as d on d.tran=a.tran
 
HTH
IP IP Logged
namitanamburi
Newbie
Newbie


Joined: 26 Mar 2009
Online Status: Offline
Posts: 39
Quote namitanamburi Replybullet Posted: 20 Jul 2009 at 2:32pm
Hi,


Thanks for the reply,

I have figured out that it is going to difficult to display the acct type and site in one row, so compromised with th eway I could retrieve it.


 

Date           Tran#    AcctType   site#  amount

 

 

10/12/2006     100       Sav                       $120.00

 

10/12/2006                                     2      $120.00

 

10/12/2006      200      chk             3      $140.00

 

10/12/2006                                    3      $140.00


After this I want to group it with the transaction number and then date and display the sum of amounts.

So when I group it as per tran date and insert the summary at the footer, the summary amount is $520, while in reality it has to be $260.


This is because one record is repeating twice.


I can suppress the display of this amount field, yet the summary is calculated from all these fields.


Please advise.


Thanks
Nammu
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Jul 2009 at 3:14pm
shared variables. 
you would want a reset and a display of the shared variable in teh header and footer of the corresponding group.  In the detail section I would put the last formula, which is the accumulator.
 
Something like this should work:
shared numbervar lastTran;
shared numbervar sumTran;
if {table.tranid}<>lastTran then (
 sumTran := sumTran + {table.tranAmount};
 lastTran := {table.tranID}
);
 
""  //suppress the calculation on the report.
 
HTH
IP IP Logged
namitanamburi
Newbie
Newbie


Joined: 26 Mar 2009
Online Status: Offline
Posts: 39
Quote namitanamburi Replybullet Posted: 22 Jul 2009 at 8:05am
Hi,

I created two formulae

formula 1 :

whileprintingrecords;
shared numbervar lastTran:= {tableA.tan#};


Formula 2:
whileprintingrecords;
shared numbervar lastTran;
shared numbervar sumTran;
if {tableA.tran#}<>lastTran then
(
lastTran := {TableA.tran#} ;
sumTran := sumTran + {TableC.amt}
);


Placed formula 1 in group header, so it is retrieving as 100 and 200.

But the sum formula has trouble


If there are three records for three different transactions and the amounts are like this grouped by Tran#

Tran#100

chk          $120

Tran# 200

saving     $140

Chk          $200


Then when we place formula 2 in the footer.of that group.


The result is


Tran#100

chk          $120
_______________
Total        $120

Tran# 200

saving     $140

Chk          $200
_______________
Total         $320


while the result Iam looking for is


Tran#100

chk          $120
_______________
Total        $120

Tran# 200

saving     $140

Chk          $200
_______________
Total         $340

_____________

Footer total  $460

_________________



please help.

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Jul 2009 at 6:11am
ok, 2 issues. 
1) by placing the summing formula in the group footer, only the last record will be read, so this will probably need to be moved to the detail section.
2) the formula will only read 1 value for a given transaction.
 
how to get around this?  I would try adding a string var, and checking if the transaction type has been used before (I am assuming that a transaction type 'checking' or 'saving' can only be used once per transaction, otherwise, you will have to rethink the report).
 
you can do this by add in formula 1:
shared stringvar usedTrans := "";
 
and in formula 2
Formula 2:
whileprintingrecords;
shared numbervar lastTran;
shared numbervar sumTran;
shared stringvar usedTrans := "";
if {tableA.tran#}<>lastTran or instr(usedTrans, {table.tranType})=0 then
(
lastTran := {TableA.tran#} ;
sumTran := sumTran + {TableC.amt}
);
 
 
you might not even need the TransNo variable.  This is what I would try.
 
HTH
 
 
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