×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

denormalize table

denormalize table

denormalize table

(OP)
We have a table like this:

QUAD    ABBR
002A    ASMAP
002A    ASMAT
007A    ERARP
007A    FRME2

We want to denormalize it like this:

002A    ASMAP,ASMAT
007A    ERARP, FRME2

I used to be able to do this stuff, but I haven't worked in Pdox for quite a while.

Harry

RE: denormalize table

Query won't do it by itself.

Create a new table.  One field for the 'unique' values.  A4, looks like.

qbe=query

:alias:table.db  | quad                          |
                 | check calc count all as nquad |

endquery
qbe.executeqbe(":alias:quadflds.db")

Index the 'newtable.db' on 'quad' (first field).  This is so you can use qlocate instead of locate[next].

Take the highest count, multiply * 5 (number of units + 1 for comma).  This will be the size of the new field in the new table.

Use 2 tcursors, one opened on 'quadflds.db', one on new table.  Note that you MUST at least attempt the unlockrecord.  Otherwise, you may well end up with really messed up records in the new table you just created.

CODE

tcO.open(":alias:original.db")
tcT.open(":alias:newtable.db")
tcT.edit()
scan tcO :
  if tcT.qlocate(tcO."quad") then
    tcT."newfield"=tcT."newfield"+","+tcO."abbr"
  else
    tcT.insertrecord()
    tcT."newfield"=tcO."abbr"
  endif
  try
    tcT.unlockrecord()
  onFail
    ; errorhandling
  endTry
endscan
tcT.endedit()
tcT.close()
tcO.close()

Haven't tested, so may contain errors.  Hopefully you get the idea, at least.

Tony McGuire
Stop Rob Bennett - http://www.notrob.info
"It's not about having enough time; we have the rest of our lives.  It's about priorities."

RE: denormalize table

(OP)
Thanks! That works.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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