I am building upon a SQl statement from the following post: Union two different tables with a primary ID field
There are two tables (md_master & cd_personal_checks) that I am trying to union into one view.
Here is my current statement.
CREATE VIEW ViewCR AS
SELECT id + 100000000000000000 AS id, a.external_code + CAST(id AS varchar(15)) as crUniqueId,
m.check_amount, 'C' as crType, m.postprint_date as activationDate,
m.postprint_date as creationDate, m.memo_explanation as reasonLine1, m.check_no
FROM MD_Master m
Join accounts a on m.account_tag = a.acct_id
WHERE (m.postprint_tag = 2) OR (m.postprint_tag = 4) OR
(m.postprint_tag = 5) OR (m.postprint_tag = 7)
UNION ALL
SELECT id + 200000000000000000 as id, 'PERCHK' + CAST(id AS varchar(15)) as crUniqueId,
check_amount, 'P' as crType, business_date as activationDate,
business_date as creationDate, identify_description as reasonLine1, check_no
FROM cd_personal_checks
HOWEVER, I have reached another obstacle. I need to get data from another table (which has a link to each of the two tables mentioned above)
In both select statments above I need to add a field called “dispositionAmount” which is the check_amount – SUM(md_cr_pending.current_amount)
md_cr_pending table has a master_id field that links with md_master.id
md_cr_pending table has a cd_personal_check_id field that links with cd_personal_checks.id
Thanks for any help
Since you did not post the third table and the forignKeys I only can help with this: