Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Loop to find like data Post Reply Post New Topic
Author Message
atmikey
Newbie
Newbie
Avatar

Joined: 02 Mar 2012
Online Status: Offline
Posts: 2
Quote atmikey Replybullet Topic: Loop to find like data
     Posted: 02 Mar 2012 at 8:45am
Hi,

How would I loop through some records to find data that is similar? for example:

NAME   PROCEDURE    DATE
bob        91             2-20
jill          91             2-20
dan        89             1-11
john       73             4-10

I want to find the two 91 procedures without explicitly saying "if {procedure}=91" Instead I need a loop that will search for procedures that are the same and have the same date without knowing what date or procedure.
Does anyone have any idea how I can do this?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Mar 2012 at 11:17am
the only way you can do this in Cr is to use a subreport....
or my favorite, make a stored proc and do the work there, set a flag or however you want to identify different groups you want to see.
 
CR doesn't allow you to read the data to search for something...it reads every line in the datatable once.  You can tell it to not display or to perform so logic, but it won't let you back up once you've found (or not) what you are looking for.
 
A subreport on the other hand is a fresh look at the data...and because it is a fresh look, it is another hit to the database, which if there are too many can make your report run slowly.
 
HTH
 
IP IP Logged
atmikey
Newbie
Newbie
Avatar

Joined: 02 Mar 2012
Online Status: Offline
Posts: 2
Quote atmikey Replybullet Posted: 05 Mar 2012 at 9:58am
Where is a good place to start to figure out how I could make a subreport do this?
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 05 Mar 2012 at 11:43am
how about a formula like
if (
distinctcount(PROCEDURE)=1 and
count(PROCEDURE) > 1
)
and
(
distinctcount(DATE )=1 and
count(DATE > 1
)
then totext(PROCEDURE) +" "+ totext(DATE) 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Mar 2012 at 12:33pm
sorry, I was being literal, and really thinking...
 
why not just group by the procedure and then have a group by the date...
then you just have to do a count, or they would display together...
you be letting CR do the work.
 
If on-the-other-hand you need the order that is displayed AND this count, then a subreport that groups by the group and link the groups and dates to the subreport should do everything you need.
 
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