Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can not get this right
Message
From
26/05/2008 00:42:35
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01319440
Message ID:
01319459
Views:
14
This message has been marked as a message which has helped to the initial question of the thread.
>Hi everybody,
>
>I can not figure out how to correctly produce the following report:
>
>I have two tables: People (cID, LName, FName) and Phones (cID, Phone, Type).
>
>There are several different types of the phones (Home, Office, Cell, E-Mail and few others).
>
>I want to display the info as
>
>Person Info - group
>
>Home   Office     Cell  E-Mail (Type)
If you want all the contact information in one row, you only need one total row per person, so you don't need grouping, it all goes in the Detail band. Your Phones table should probably be renamed to something like Contacts.

One approach is something like this:
SELECT ;
  LName ;
  , FName ;
  , GetContactInfo( cID, "Home" ) AS Contact1 ;
  , GetContactInfo( cID, "Office" ) AS Contact2 ;
  , ... ;
  FROM People ;
  ...

FUNCTION GetContactInfo( tcID, tcContactType )
LOCAL ;
  lcRetVal

SELECT ;
  Phone ;
  FROM Phones ;
  WHERE Phones.cID == tcID ;
    AND Phones.Type == tcContactType ;
  ...

IF _TALLY > 0
  lcRetVal = ...

ELSE
  lcRetVal = ""

ENDIF

RETURN lcRetVal
One problem with this approach is if you add even one Contact type, you have to add a column to your main SELECT. Then you have to remember to add another Contact column in your report.

Another approach is to lump all the Contact information into a single Memo field:
SELECT ;
  LName ;
  , FName ;
  , CAST( GetContactInfo( cID ) AS M ) AS ContactInfo ;
  , ... ;
  FROM People ;
  ...

FUNCTION GetContactInfo( tcID )

* This function gets all the Contact info for a single Person and formats it in
* a character string, with CRLFs if desired

RETURN SomeCharString
With this second approach, your report contains just a single field to hold the memo so the report doesn't have to be changed later. You just have to update the GetContactInfo() function if you add types.

You can see why some people just leave the report like this <g> :
Person Info (group)
  Home
  Office
  Cell
  E-mail
  ...
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform