Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I posted a query a short while ago and had an informed answer within a couple of hours. Terrific!..."

Geography

Where in the world do Tek-Tips members come from?
mherz715 (Programmer)
26 Apr 12 4:32
Hi!
 I have a problem regarding on my data.see sample below:
 In my table1 I have two fields:
    PRODUCT#    DESCRIPTION     
    A516        PRODUCT#1         
    A516        PRODUCT#2         
    B200        PRODUCT#3         
    B200        PRODUCT#4         
 Now, what I want to do is to tag the data with the same product#. (for report purposes only) Like this:
PRODUCT#    DESCRIPTION      TAG
  A516      PRODUCT#1         1
  A516      PRODUCT#2         1
  B200      PRODUCT#3         2
  B200      PRODUCT#4         2

Is this possible using For.. next loop?? or any suggestion that this data make possible.

Thank in advance.
MikeLewis (Programmer)
26 Apr 12 5:00
I would do this with some SQL rather than a FOR loop.

Here is a first stab at it. I haven't tested this, but it should give you the general idea.

CODE

* Group the original data
SELECT Product FROM MyTable ;
  GROUP BY Product
  INTO CURSOR ProdGroups

* Add the record number as the tag
SELECT Product, RECNO() AS Tag FROM ProdGroups ;
  INTO CURSOR ProdGroups1

* Combine the original data with the tag
SELECT my.Product, my.Description, gr.Tag ;
  FROM MyTable my JOIN ProdGroups1 gr ON my.Product = gr.Product ;
  INTO CURSOR Result

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

mm0000 (IS/IT--Management)
26 Apr 12 10:50

select * from table1 order by prodno into cursor temp readwrite

alter table temp add tag n(5) && add column tag

locate
lncount = 0

do while not eof()
   lncount = lncount + 1
   lcprodno = prodno
   do while prodno = lcprodno
      replace tag with lncount
      skip
   enddo
enddo

 

OlafDoschke (Programmer)
26 Apr 12 11:01
>(for report purposes only)

Then add a group into your report, grouping on product# and a report variable counting up +1 with each group change would be your tag number.

Bye, Olaf.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close