Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: create a report using 2 different databases Post Reply Post New Topic
Author Message
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Topic: create a report using 2 different databases
     Posted: 14 Jun 2013 at 4:31am
I have two separate reports for Company A and Company B, they are both working on the same project and so I would like to create a report that contains all of their appointments and the status in one report.

First problem I have is that both companies have the same table names, when I bring the other table over it does give it a "_1" to the name.

Second problem is that they do not use the same ID for the people in the two different companies, however, the name, dob, ssn, is the same.

For my reports I am using the following tables:
Company A (same tables in Company B just a different db):
Patient Profile
Patient Visit
Patient Insurance
Insurance Carriers ID
Appointments
ApptTypes

I'm beating my head against the wall because no matter how I try to join them I cannot get Company B's appointments to show up in the list along with Company A's.

I am using Crystal Reports 2011 and Windows 7 if that makes a difference. Database one Tables are in CPSSQL and the other tables are in MPCCPS. So for each one I click on the +in front of CPSSQL or MPCCPS then click on the + for MBC or MPC to dbo to the Tables...

Any suggestions would be much appreciated. Thank you.
Michele
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 14 Jun 2013 at 8:06am
What you designate as a problem with "_1" appearing on the table names is actually not a problem.  When a specific table name is already used in the report, Crystal will automatically "alias" the second table with the same name by adding "_1" to the end of the name.  This is just an alias, not the actual table name.
 
The problem I suspect you're going to run into is that you'll have some patients that have appointments with only Company A and some with appointments with only Company B.  So just linking tables together is not going to work for you. 
 
Based on some of the wording in your question, I assume that you're connecting to SQL Server - is that correct? If it is, there's a way of running a query on one DB and "linking" to another DB to get data from there as well.  How good are your SQL skills?  In Crystal you could write a single Command (SQL Select statement) in the report that will union together the data from both databases to get what you're looking for.  There are a couple of things to remember when using commands:
 
1.  If you're using a command, always include ALL of the data you need for your report in a single command.  Although you can link tables and commands, it can significantly impact the speed of the report.
 
2.  Any filtering of the data needs to happen in the command - do not use the Select Expert to filter the data.
 
3.  If you're using parameters to filter the data, DO NOT create the parameters in the Field Explorer in the report.  Instead, create them in the Command Editor.  They will then appear in the Field Explorer in the report.  There are some additional "behind the scenes" properties of parameters that are created in the Command Editor that aren't in the ones created in the Field Explorer and Crystal isn't able to use parameters created in the Field Explorer inside commands.
 
-Dell
IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 14 Jun 2013 at 10:25am
My SQL is NOT good. Is this even the right path to take? This is a Command. My question then is how do you do a "Union"?

SELECT DB='MPC', "PatientProfile"."PatientId", "PatientProfile"."Last", "PatientProfile"."First", "ApptType"."Name" AS ApptType, "Appointments"."Status" AS ApptStatus, "InsuranceCarriers"."InsuranceGroupId", "Appointments"."ApptStart", "InsuranceCarriers"."ListName" AS InsName, "Cases"."Name" AS CaseName, "PatientProfile"."searchname" AS PTFullName
FROM   ((("mpc"."dbo"."Appointments" "Appointments" INNER JOIN "mpc"."dbo"."ApptType" "ApptType" ON "Appointments"."ApptTypeId"="ApptType"."ApptTypeId") INNER JOIN "mpc"."dbo"."Cases" "Cases" ON "Appointments"."CasesId"="Cases"."CasesId") INNER JOIN "mpc"."dbo"."InsuranceCarriers" "InsuranceCarriers" ON "Cases"."PrimaryInsuranceCarriersId"="InsuranceCarriers"."InsuranceCarriersId") INNER JOIN "mpc"."dbo"."PatientProfile" "PatientProfile" ON "Cases"."PatientProfileId"="PatientProfile"."PatientProfileId"
WHERE ("Cases"."Name"='HOPE' OR "Cases"."Name"='PT') AND ("InsuranceCarriers"."ListName" LIKE 'PH%' OR "InsuranceCarriers"."ListName" LIKE 'Priority%') AND "InsuranceCarriers"."InsuranceGroupId"=43
ORDER BY "PatientProfile"."searchname", "PatientProfile"."Last", "PatientProfile"."First", "Appointments"."ApptStart"
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 17 Jun 2013 at 4:19am
Assuming that "MPC" is the "Company A" database, you can replace "<CompanyB db> in the following to get what you're looking for:
 
SELECT
  PatientProfile.PatientId,
  PatientProfile.Last,
  PatientProfile.First,
  ApptType.Name AS ApptType,
  Appointments.Status AS ApptStatus,
  InsuranceCarriers.InsuranceGroupId,
  Appointments.ApptStart,
  InsuranceCarriers.ListName AS InsName,
  Cases.Name AS CaseName,
  PatientProfile.searchname AS PTFullName
FROM  mpc.dbo.Appointments Appointments
  INNER JOIN mpc.dbo.ApptType ApptType ON Appointments.ApptTypeId=ApptType.ApptTypeId
  INNER JOIN mpc.dbo.Cases Cases ON Appointments.CasesId=Cases.CasesId) INNER JOIN mpc.dbo.InsuranceCarriers InsuranceCarriers ON Cases.PrimaryInsuranceCarriersId=InsuranceCarriers.InsuranceCarriersId) INNER JOIN mpc.dbo.PatientProfile PatientProfile ON Cases.PatientProfileId=PatientProfile.PatientProfileId
 WHERE (Cases.Name='HOPE' OR Cases.Name='PT')
   AND (InsuranceCarriers.ListName LIKE 'PH%' OR InsuranceCarriers.ListName LIKE 'Priority%')
   AND InsuranceCarriers.InsuranceGroupId=43
 ORDER BY PatientProfile.searchname, PatientProfile.Last, PatientProfile.First, Appointments.ApptStart
 
 UNION
 
 SELECT
   PatientProfile.PatientId,
   PatientProfile.Last,
   PatientProfile.First,
   ApptType.Name AS ApptType,
   Appointments.Status AS ApptStatus,
   InsuranceCarriers.InsuranceGroupId,
   Appointments.ApptStart,
   InsuranceCarriers.ListName AS InsName,
   Cases.Name AS CaseName,
   PatientProfile.searchname AS PTFullName
 FROM  <CompanyB db>.dbo.Appointments Appointments
   INNER JOIN <CompanyB db>.dbo.ApptType ApptType ON Appointments.ApptTypeId=ApptType.ApptTypeId
   INNER JOIN <CompanyB db>.dbo.Cases Cases ON Appointments.CasesId=Cases.CasesId) INNER JOIN <CompanyB db>.dbo.InsuranceCarriers InsuranceCarriers ON Cases.PrimaryInsuranceCarriersId=InsuranceCarriers.InsuranceCarriersId) INNER JOIN <CompanyB db>.dbo.PatientProfile PatientProfile ON Cases.PatientProfileId=PatientProfile.PatientProfileId
  WHERE (Cases.Name='HOPE' OR Cases.Name='PT')
    AND (InsuranceCarriers.ListName LIKE 'PH%' OR InsuranceCarriers.ListName LIKE 'Priority%')
    AND InsuranceCarriers.InsuranceGroupId=43
 ORDER BY PatientProfile.searchname, PatientProfile.Last, PatientProfile.First, Appointments.ApptStart
 
-Dell
IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 02 Jul 2013 at 3:50am
Thanks so MUCH!!!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum