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

  • Home
  • SEARCH
  • 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 7636439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:40:50+00:00 2026-05-31T07:40:50+00:00

I wrote two queries below that produce one row of data each. What is

  • 0

I wrote two queries below that produce one row of data each.

What is the best way to combine them such that I am LEFT with only a single row of data?

These are coming FROM two DISTINCT databases named : [ASN01] and [dsi_ASN_dsicx]

I have 70 pairs of databases like this but am showing only one for simplicity.

The fact that the three letter acronym ASN is common to both database names is no mistake and if needed can be a part of the solution.

Current Results:

Site, Elligence (header)
ASN, 100.00

Site, GP_Total (header)
ASN, 120.00

Desired results:

Site, GP_Total, Elligence (header)
ASN, 120.00, 100.00

SELECT  'ASN' AS Site ,
        CASE SUM(perdblnc)
          WHEN NULL THEN 0
          ELSE -1 * SUM(PERDBLNC)
        END AS GP_Total
FROM    [ASN01].[dbo].[GL10110] T1
        LEFT OUTER JOIN [ASN01].[dbo].[GL00105] T2 ON [T1].[ACTINDX] = [T2].[ACTINDX]
WHERE   YEAR1 = 2012
        AND PERIODID IN ( '2' )
        AND ACTNUMST IN ( '4200-0000-C', '6940-0000-C', '6945-0000-C',
                          '6950-0000-C' )

SELECT  'ASN' AS [Site] ,
        SUM(pi.amount) AS [Elligence]
FROM    [dsi_ASN_dsicx].dbo.charge c
        LEFT JOIN [dsi_ASN_dsicx].dbo.paymentitem pi ON c.idcharge = pi.chargeid
        LEFT JOIN [dsi_ASN_dsicx].dbo.payment p ON pi.paymentid = p.idpayment
        LEFT JOIN [dsi_ASN_dsicx].dbo.paymenttype pt ON p.paymenttypeid = pt.idpaymenttype
WHERE   pi.amount != 0
        AND pt.paymentmethod NOT IN ( '5', '7' )
        AND pt.paymentmethod IS NOT NULL
        AND p.sdate >= '20120201'
        AND p.sdate <= '20120229'
  • 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-05-31T07:40:51+00:00Added an answer on May 31, 2026 at 7:40 am

    WIthout going through and changing any of your queries, the easiest way would be to use temp tables using the “WITH” common_table_expression. Table1 and Table2 are temp tables created from your select statements. Therefore, we select table1 and join table2.

    Let me know if there are any syntax problems, I don’t have anything to test this on presently.

    ;With Table1 as (SELECT 'ASN' as Site, Case sum(perdblnc) 
    WHEN NULL THEN 0 
    ELSE -1*sum(PERDBLNC) END as GP_Total  
    FROM [ASN01].[dbo].[GL10110] T1
    Left Outer Join [ASN01].[dbo].[GL00105]  T2
    ON [T1]. [ACTINDX]= [T2]. [ACTINDX]
    WHERE YEAR1 = 2012
    AND PERIODID in ('2')
    AND ACTNUMST in ('4200-0000-C', '6940-0000-C', '6945-0000-C', '6950-0000-C'))
    
    , Table2 as (SELECT 
        'ASN' as [Site],
        SUM(pi.amount) as [Elligence]
    FROM [dsi_ASN_dsicx].dbo.charge c
        LEFT JOIN [dsi_ASN_dsicx].dbo.paymentitem pi on c.idcharge = pi.chargeid
        LEFT JOIN [dsi_ASN_dsicx].dbo.payment p on pi.paymentid = p.idpayment
        LEFT JOIN [dsi_ASN_dsicx].dbo.paymenttype pt on p.paymenttypeid = pt.idpaymenttype
    WHERE pi.amount != 0
    AND pt.paymentmethod not in ('5','7')
    AND pt.paymentmethod is not null
    AND p.sdate >='20120201' and p.sdate <= '20120229')
    
    SELECT * FROM Table1
    LEFT JOIN Table2 ON Table1.site = Table2.site
    

    Hope this helps! Marks as answer if it is =)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote two queries to find duplicates in the array var groups = from
I am a beginner in JavaScript but I wrote two functions that is meant
I wrote a PHP-CLI script that mixes two audio (.WAV PCM) files (with some
I have wrote an application that syncs two folders together. The problem with the
Inspired by this question on Meta , I wrote two queries on the Stack
I wrote a JSP code that needs to run some mysql INSERT queries that
I could use some suggestions / ideas. I wrote a console application that queries
I'd like to ask for help with the two queries below. They work like
I have a DB with postgresql and I wrote two simple queries select page
I wrote a python script that: 1. submits search queries 2. waits for 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.