Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Connecting two databases and connecting by date 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: Connecting two databases and connecting by date
     Posted: 31 Jul 2013 at 9:21am
I am using two different databases, uvPatientDemographics and Michele_View.token, to try and get all appointments with the patient reference source = "Hope" and then grab the data in Michele View, to receive the survey scores they took on a date of service. Inputting the below, all I get are the appointments that have an appointment date in the Michele View. Doesn't seem to matter how I connect the link between the two - I get the same info. I tried "or" but that gave me everyone... because it either equals Hope or its the rest, so that doesn't work. I'm sure there is some way to word this correctly to get what I want, but it's getting the best of me.

from the patient demographics, all patient appointments must equal apptkind 1 and patient reference source must equal Hope. So if patient a is
John Doe Hope 4/14/2013 and his status is no show, the values for the survey portion should be null. if on his appointment on 5/15/2013 he completed a survey, then the values of those fields would be entered on the report and so on.



{Appointments.ApptKind} = 1 and
{uvPatientDemographics.PatientReferenceSource} = "Hope" and
ToText({Appointments.ApptStart}, 'MM/dd/yyyy') = ToText({Michele_View.token}, 'MM/dd/yyyy')


Any ideas would be appreciated. Thank you.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Aug 2013 at 5:16am
Have you thought of using a stored proc. In the proc it should be simple to reference the other database...or you could have a synonym created in one database that references a table in another database, and then you can use the synonym as if it were a local table to the database.

just some thoughts,
HTH
IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 02 Aug 2013 at 5:19am
We were discussing that... but not sure how to connect two reports in one.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Aug 2013 at 5:08am
it's just setting data sources and some value that can be used to retrieve the data in a subreport to the main report...or it's a synonym and use that to join the 2 tables together to retrieve the data.

it's all basically the same, as you need to get data out of one database based on a value from the other, and then display it.

HTH
IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 05 Aug 2013 at 5:29am
Okay, so Report 1, which is the main report I am pulling PatientID, PatientRef, PatientFullName, ApptName, ApptStart, FacilityName and Status. This gives me all of their appointments and whether they arrived/no showed/rescheduled, etc. Report 2, which I need to pull info in from comes from a different DB, and in that report I pull PatientID, PatientFullName, TokenDate, and then survey answer fields Activity, Mood, Walk, Relationships, Work, Sleep, Enjoy, Overall relief, Patient Satisfaction Average.

What is driving me crazy is that in report 1, apptstart is a specific date/time, and in report 2, tokendate is the specific date - but time is always 12am and so don't match.

It seems easy enough to say if Patient x had a visit in report 1 and a visit in report 2 that = same day then add survey scores but all I get is the info where both dates are equal.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 05 Aug 2013 at 5:34am
since the data in rpt2 is at midnight, create a formula to translate your apptstart to midnight of the same day...
something like:
cdate(year({table.apptstart}), month({table.apptstart}), day({table.apptstart}))

cdate may be the wrong command, but it will be something close...

now link the report to the subreport using the formula, which should work now since the dates are the same.

HTH
IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 05 Aug 2013 at 9:33am
would you happen to have an email I can send you a pdf of... because I added the subreport in, but that just lists everything at the end, and for some reason I'm hitting a brick wall. my email is mmarkel@procaresystems.com
IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 06 Aug 2013 at 6:45am
Below is the SQL Query that I've got so far. It gives me 193 records and the total I need is 1859. So this is still only giving me data in MPCCPS that is in Limesurveydev, when I need all data in MPCCPS.

jdbc:mysql://limesurveydev/limesurveydev
SELECT `Michele_View`.`99946X10X1391`, `Michele_View`.`99946X10X1293`, `Michele_View`.`token`
FROM   `limesurveydev`.`Michele_View` `Michele_View`
EXTERNAL JOIN Michele_View.99946X10X1293={?MPCCPS: Command_1.OwnerId} AND Michele_View.token={?MPCCPS: Command_1.DateLink}


MPCCPS
SELECT "uvPatientDemographics"."PatientReferenceSource", "uvPatientDemographics"."FacilityName", "uvPatientDemographics"."PatientFullName", "uvPatientDemographics"."PatientId", "Appointments"."ApptKind", "Appointments"."ApptStart", DATEADD(dd, 0, DATEDIFF(dd, 0, "Appointments"."ApptStart")) as "DateLink", "Appointments"."Status", "ApptType"."Name", "Appointments"."OwnerId"
FROM   (("mpc"."dbo"."PatientProfile" "PatientProfile" INNER JOIN "mpc"."dbo"."Appointments" "Appointments" ON "PatientProfile"."PatientProfileId"="Appointments"."OwnerId") INNER JOIN "mpc"."dbo"."uvPatientDemographics" "uvPatientDemographics" ON "PatientProfile"."PatientProfileId"="uvPatientDemographics"."PatientProfileId") INNER JOIN "mpc"."dbo"."ApptType" "ApptType" ON "Appointments"."ApptTypeId"="ApptType"."ApptTypeId"
WHERE "Appointments"."ApptStart">={ts '2012-07-16 10:30:01'} AND "Appointments"."ApptKind"=1 AND "uvPatientDemographics"."PatientReferenceSource"='Hope'
ORDER BY "uvPatientDemographics"."PatientFullName"
EXTERNAL JOIN Command_1.OwnerId={?jdbc:mysql://limesurveydev/limesurveydev: Michele_View.99946X10X1293} AND Command_1.DateLink={?jdbc:mysql://limesurveydev/limesurveydev: Michele_View.token}
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 06 Aug 2013 at 11:04am
I don't know how different mySQL is from SQL Server...
Is the external join an inner or outer join? It would seem to be inner, and I would think that you need outer.

IP IP Logged
MicheleM
Newbie
Newbie
Avatar

Joined: 05 Apr 2011
Location: United States
Online Status: Offline
Posts: 26
Quote MicheleM Replybullet Posted: 07 Aug 2013 at 6:59am
Finally got the above to work... such a simple fix it was... but now I'm trying to join in another database and my errors are "incorrect syntax" near the "Where" statements are.

SELECT DB='MPC', "uvPatientDemographics"."PatientReferenceSource", "uvPatientDemographics"."FacilityName", "uvPatientDemographics"."PatientFullName", "uvPatientDemographics"."PatientBirthDate", "uvPatientDemographics"."PatientId", "Appointments"."ApptKind", "Appointments"."ApptStart", DATEADD(dd, 0, DATEDIFF(dd, 0, "Appointments"."ApptStart")) as "DateLink", "Appointments"."Status", "ApptType"."Name", "Appointments"."OwnerId"

FROM ((("mpc"."dbo"."PatientProfile" "PatientProfile" INNER JOIN "mpc"."dbo"."Appointments" "Appointments" ON "PatientProfile"."PatientProfileId"="Appointments"."OwnerId") INNER JOIN "mpc"."dbo"."uvPatientDemographics" "uvPatientDemographics" ON "PatientProfile"."PatientProfileId"="uvPatientDemographics"."PatientProfileId") INNER JOIN "mpc"."dbo"."ApptType" "ApptType" ON "Appointments"."ApptTypeId"="ApptType"."ApptTypeId"

WHERE "Appointments"."ApptStart">={ts '2012-07-16 10:30:01'} AND "Appointments"."ApptKind"=1 AND "uvPatientDemographics"."PatientReferenceSource"='Hope'


UNION

SELECT DB='MBC', "uvPatientDemographics"."PatientReferenceSource", "uvPatientDemographics"."FacilityName", "uvPatientDemographics"."PatientFullName", "uvPatientDemographics"."PatientBirthDate", "uvPatientDemographics"."PatientId", "Appointments"."ApptKind", "Appointments"."ApptStart", DATEADD(dd, 0, DATEDIFF(dd, 0, "Appointments"."ApptStart")) as "DateLink", "Appointments"."Status", "ApptType"."Name", "Appointments"."OwnerId"

FROM ((("cpssql"."mbc"."dbo""PatientProfile" "PatientProfile" INNER JOIN "mbc"."dbo"."Appointments" "Appointments" ON "PatientProfile"."PatientProfileId"="Appointments"."OwnerId") INNER JOIN "cpssql""mbc"."dbo"."uvPatientDemographics" "uvPatientDemographics" ON "PatientProfile"."PatientProfileId"="uvPatientDemographics"."PatientProfileId")
INNER JOIN "cpssql""mbc"."dbo"."ApptType" "ApptType" ON "Appointments"."ApptTypeId"="ApptType"."ApptTypeId"

WHERE "Appointments"."ApptStart">={ts '2012-07-16 10:30:01'} AND "Appointments"."ApptKind"=1 AND "uvPatientDemographics"."PatientReferenceSource"='Hope'

ORDER BY "uvPatientDemographics"."PatientFullName"

The problem with DB1 and DB2 is that the patientID's are not the same, however for the limesurveydev and DB1 they are the same. So DB2 has to be pulled over by patient name and birthdate... all need to euql Patient Reference Source "Hope" and all appointments after 6/30/2012.

Ideas?????
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