Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

denormalize table

Status
Not open for further replies.

harrymossman

Technical User
Sep 5, 2002
255
US
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
 
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 - "It's not about having enough time; we have the rest of our lives. It's about priorities.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top