Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Statement Help
Message
 
To
20/05/2013 15:21:42
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01574323
Message ID:
01574324
Views:
86
This message has been marked as a message which has helped to the initial question of the thread.
>I have three tables set up as follows:
>
>
>CallReports Table
>
> CallReport_Id        etc...
>1
>2
>3
>
>
>
>CallReport_Users Table
>
>CallReport_Id         UserId
>1                             A
>2                             A
>2                             B
>2                             C
>3                             C
>
>
>CallReport_Companys Table
>
>CallReport_id         Company_id
>1                                G
>1                                H
>2                                M
>3                                K
>
>
>I would like a single cursor/table that shows a single line for each callreport_id and either the userid, if a single entry, or the word 'Multiple,' if there are multiple userids for a callreport_id. The same for the company_id. For example:
>
>
>CallReport_id                 UserId                          Company_id
>1                                   A                                 'Multiple'
>2                                  'Multiple'                        M
>3                                  C                                  'Multiple'
>
>
>Can someone provide some guidance on how to accomplish this?
>
>Thanks in advance,
>Russell
SELECT CallReports.*,;
       CAST(IIF(CRUsers.Cnt > 1, "Multiple", CRUsers.UserId) as C(???) AS UserId,;
       CAST(IIF(CRComp.Cnt > 1 , "Multiple", CRComp.Company) as C(???) AS Company;
FROM CallReports;
INNER JOIN  (SELECT CallReport_Id, MAX(UserId) AS UserId, COUNT(*) AS Cnt;
                    FROM CallReport_Users;
             GROUP BY CallReport_Id) CRUsers ON CRUsers.CallReport_Id = CallReports.CallReport_Id;
INNER JOIN  (SELECT CallReport_Id, MAX(Company_Id) AS Company, COUNT(*) AS Cnt;
                    FROM CallReport_Companys;
             GROUP BY CallReport_Id) CRComp ON CRComp.CallReport_Id = CallReports.CallReport_Id;
INTO CURSOR crsTest
BROW NORMAL
NOT TESTED!
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform