Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:31:21+00:00 2026-06-10T22:31:21+00:00

I am building upon a SQl statement from the following post: Union two different

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:31:22+00:00Added an answer on June 10, 2026 at 10:31 pm

    Since you did not post the third table and the forignKeys I only can help with this:

    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,
        m.check_amount - sh.sumAmount As Difference 
        FROM MD_Master m
        Join accounts a on m.account_tag = a.acct_id
        INNER JOIN (SELECT forignKeyID, 
                    SUM(md_cr_pending.current_amount) as sumAmount 
                    FROM Table 3
                    Group BY forignKeyID) sh ON sh.forignKeyID = m.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,
        check_amount - sh.sumAmount As Difference 
        FROM cd_personal_checks 
        INNER JOIN (SELECT forignKeyID, 
                    SUM(md_cr_pending.current_amount) as sumAmount 
                    FROM Table 3
                    Group BY forignKeyID) sh 
                    ON sh.forignKeyID = cd_personal_checks.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

building upon the $.fn.serializeObject() function from this question , i'd like to be able
Building my solution succeeds, but the build fails upon copying from the build to
I am building a web application that is dependent upon several third-party libraries. What
I'm building a Rails app which creates a bookmarklet file for each user upon
I'm building a web service that executes a database process (SQL code to run
I am building an application that calls upon a compiled executable. Said executable's source
I am building an win32 application that is statically linked with OpenCV libraries. Upon
Upon building an MVC framework in PHP I ran into a problem which could
I'm building a web application that relies upon the Facebook API. I want to
Lets say I'm building a base class which will be extended upon by the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.