Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: looping through records from formula editor Post Reply Post New Topic
Author Message
aacid
Newbie
Newbie


Joined: 19 Nov 2012
Location: Slovakia
Online Status: Offline
Posts: 2
Quote aacid Replybullet Topic: looping through records from formula editor
    Posted: 20 Nov 2012 at 12:03am
hi,
I have accounts table, each account has level and its father account.

acct      father      level
1111      1110        4
1110      1100        3
1100      1000        2
1000      0000        1

what I need is to assign father account to each account on my report on level specified by user.
so when user selects level 2 account 1100 will be 1111's father, if he selects 3 father will be 1110.

it was easy in c++, I just repeated "select father from table" until account was number specified. but I have no idea how to do this on crystal report.
SQL expression does not allow variables, that was my only idea so far...
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 20 Nov 2012 at 1:12am
Hi
 
The table info and description are not tallying... can you check this and update your post ?
----------
 
acct father level
1111 1110 4
1110 1100 3
1100 1000 2
1000 0000 1

what I need is to assign father account to each account on my report on level specified by user.
so when user selects level 2 account 1100 will be 1111's father, if he selects 3 father will be 1110.
Thanks,
Sastry
IP IP Logged
aacid
Newbie
Newbie


Joined: 19 Nov 2012
Location: Slovakia
Online Status: Offline
Posts: 2
Quote aacid Replybullet Posted: 20 Nov 2012 at 1:58am
I don't see any error, maybe just my explanation is confusing, sorry.

user selects level from dropdown menu with values 1-3. for example he chooses level 2:
output will be:
acct father
1111 1000
2222 2000
1234 1000

if user chooses different level (2), report grouping should change as:
acct father
1111 1100
2222 2200
1234 1200

problem is in account table, for each account there is only stored direct parent.
algorithm looks like this:
next_parent, level = SELECT father, level FROM ACCT WHERE account = {account from report}

while level != {users selection}
do
next_parent, level = SELECT father, level FROM ACCT WHERE account = next_parent
end while


I just have no idea how to do it in crystal reports
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 20 Nov 2012 at 3:23am
I would do this in a stored proc or preprocess the data in your application and pass the results to the report. 
CR basically presents 1 row at a time, to the report to process.  so you can't really loop through the data or hit the database again.
 
A subreport might help, but it too will only process 1 record at a time, but it will hit the database again which might help.
 
we use a combination of our app getting the data via a stored proc, processing the dataset as needed and then 'pushing' it to CR which gives us plenty of flexibility in data manipulation, and leaves CR to what it does best...displaying data.
 
HTH
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.016 seconds.