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