Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Combining string fields with duplicated data Post Reply Post New Topic
Author Message
Jesse
Newbie
Newbie


Joined: 05 Feb 2010
Online Status: Offline
Posts: 7
Quote Jesse Replybullet Topic: Combining string fields with duplicated data
     Posted: 17 Aug 2010 at 6:34am
Hello,

I am trying to combine the detail of a particular field on one line using the Ken Hamady formula found here, http://www.kenhamady.com/form16.shtml, for appending a list of detail on one line.

The formula works great but unfortunately the data in my tables is bad and gives me two or more details with the same string for each unique detail. I am trying to remove the duplicated string so that the formula will only show unique details separated by commas. Here is the formula and an example of what the data then looks like:

WhilePrintingRecords;
    StringVar Item:= {OrderItemsAttributes.AttributeDetailName}; // place your field in place of {Your.Field}
    StringVar Chain;
    NumberVar ChCnt;

    if ChCnt = 1
    then (ChCnt:= 2; chain := Item)
    else
    if Length(Chain) + Length(Item) > 254  //see note about this number below
    then Chain := Chain else
    chain := chain + ', ' + Item

End data looks like:

1lb - $9.45, 1lb - $9.45, Whole Bean, Whole Bean or
5 - 1lb - $42.52, 5 - 1lb - $42.52, Whole Bean, Whole Bean

Unfortunately, I can't access or fix the database that I am getting this info from. It will become obsolete for us in a few months so the company is not willing to try and to fix the data.

Does anyone have any suggestions?

Thanks!

Jesse




IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 17 Aug 2010 at 7:50am
Try this:
WhilePrintingRecords;
  StringVar Item:= {OrderItemsAttributes.AttributeDetailName}; 
  StringVar Chain;
  NumberVar ChCnt;

  if InStr(Chain, Item) > 0 then
    if ChCnt = 1 then
      (ChCnt:= 2; chain := Item)
    else
      if Length(Chain) + Length(Item) > 254 then
        Chain := Chain
    else  chain := chain + ', ' + Item
  else Chain := Chain
 
The call to Instr() checks to make sure that the item isn't already in the list.
 
-Dell
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