Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: searching for duplicate field Post Reply Post New Topic
Author Message
draven422
Newbie
Newbie


Joined: 21 Apr 2009
Online Status: Offline
Posts: 11
Quote draven422 Replybullet Topic: searching for duplicate field
    Posted: 28 Oct 2009 at 2:24pm
I am trying to create a formula in a report that will display a flag if a certain field is duplicated.
Right now I have:
if Name = previous(Name) then "Y"
 
Since that will only look at the previous return, I am limited to them side-by-side.  Is there something that can be written to set the flag if it matches any of the returns?  I was going to sort by that Name field, but the listing needs to be in a specific sort order (sequential).
 
Any help is greatly appreciated.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Oct 2009 at 6:25am
a variable, I like shared, but global would work.
Create a delimited string of, in this case names, and then search if the name exists.  Something like:
shared stringvar allNames;
 
if instr(allNames, "|" + Name + "|")>0 then
  "Y"
else(
  allNames := allNames +  "|" + Name + "|";
  "N"//or could be "" the empty string
)
 
you create a string that allows for unique identification of a name and then you search it. If you find it, you set your flag, if not, you can set or not set a flag--and you add the value for future searches.
 
HTH
IP IP Logged
draven422
Newbie
Newbie


Joined: 21 Apr 2009
Online Status: Offline
Posts: 11
Quote draven422 Replybullet Posted: 29 Oct 2009 at 7:13am
You da man!
 
Thank you so much.  That worked perfectly.
IP IP Logged
draven422
Newbie
Newbie


Joined: 21 Apr 2009
Online Status: Offline
Posts: 11
Quote draven422 Replybullet Posted: 29 Oct 2009 at 7:22am
OK, I have to throw a monkey wrench into it already.
 
Would it be easy to have the flag show what record it matched with?  Something like "Duplicate to record 123."
 
Thanks again!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Oct 2009 at 8:59am
yeah, just need to add the record number in as another field, so you can change it to:
shared stringvar allNames;
shared stringvar rec;
local numbervar ind :=  instr(allNames, "|" + Name + "^");
local numbervar carat;
 
if ind>0 then (
  carat := instr(ind, allNames, "^");
  ind := instr(carat, allNames, "|");
  rec := mid(allNames, carat+1,  ind - carat - 2);
  "Y"
)
else(
  allNames := allNames +  "|" + Name + "^" + RecordNumber;
  "N"//or could be "" the empty string
)
 
then in another formula you can access the recordNumber via
shared stringvar rec
 
Glad I could help.
IP IP Logged
draven422
Newbie
Newbie


Joined: 21 Apr 2009
Online Status: Offline
Posts: 11
Quote draven422 Replybullet Posted: 29 Oct 2009 at 11:30am
Thanks again lockwelle.
 
I must've missed something.  I get an error stating, "String length is less than 0 or not an integer."  It then opens the formula highlighting the rec variable.  I'm assuming it was hitting on the AllNames variable, because when I set it to null, it doesn't error, but it doesn't flag the duplicate.
IP IP Logged
draven422
Newbie
Newbie


Joined: 21 Apr 2009
Online Status: Offline
Posts: 11
Quote draven422 Replybullet Posted: 29 Oct 2009 at 12:57pm

I think I fixed it.  I put in a check to make sure it wasn't going into a negative number.

 
shared stringvar allNames;
shared stringvar rec;
local numbervar ind :=  instr(allNames, "|" + Name + "^");
local numbervar carat;
if ind>0 then (
  carat := instr(ind, allNames, "^");
  ind := instr(carat, allNames, "|");
  if carat > ind then (
    rec := mid(allNames, carat+1,  carat - ind - 2);
    "Y";
  ) else(
    rec := mid(allNames, carat+1,  ind - carat - 1);
    "Y";
  )
)
else(
  allNames := allNames +  "|" + Name + "^" + RecordNumber;
  ""
)


Edited by draven422 - 29 Oct 2009 at 12:57pm
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 30 Oct 2009 at 6:10am
oops!
allNames := allNames +  "|" + Name + "^" + RecordNumber;
should be:
allNames := allNames +  "|" + Name + "^" + RecordNumber + "|";
it's what I envisioned when I was writing the equation.  The string was |Name|, then adding the record # was to change it to |Name^Record|
 
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.032 seconds.