Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Union statement help Post Reply Post New Topic
Author Message
sanchezgmc06
Senior Member
Senior Member
Avatar

Joined: 21 Jan 2011
Online Status: Offline
Posts: 107
Quote sanchezgmc06 Replybullet Topic: Union statement help
     Posted: 23 Jul 2014 at 3:40pm
Hello I wrote my first union statement however I need to incorporate another part into the sql and I am not sure how to do about doing so.

Below is my union statement

SELECT
PAF.partnership_date AS ASSMT_DTE,
PAF.PATID AS PATIENT_ID,
PAF.assessment_status_value AS ASSMT_STATUS,
PAF.PAFuniqueid as ID
FROM
SYSTEM.mhsa_part_assess_form PAF

UNION

SELECT
KET.date_completed,
KET.PATID,
KET.assessment_status_value,
KET.KETuniqueid
FROM
SYSTEM.mhsa_key_event_tracking KET

UNION

SELECT
QAF.date_completed,
QAF.PATID,
QAF.assessment_status_value,
QAF.QASuniqueid
FROM
SYSTEM.mhsa_quarterly_assessment QAF


And the part I need to add to that statement is below

SELECT
TPD.program_value,
TPD.program_X_full_svc_p_p_id
FROM
SYSTEM.table_program_definition TPD
WHERE
TPD.program_X_full_svc_p_p_id IS NOT NULL

Thank you!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 25 Jul 2014 at 5:05am
you will need to add 'dummy' values for the missing fields.

A union needs the same types and number of columns for all of the selects

HTH
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 25 Jul 2014 at 6:55am
as lockwelle  said something like this

SELECT
null,
null,
TPD.program_value,
TPD.program_X_full_svc_p_p_id

FROM
SYSTEM.table_program_definition TPD
WHERE
TPD.program_X_full_svc_p_p_id IS NOT NULL
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