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 6555361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:48:37+00:00 2026-05-25T12:48:37+00:00

I am newbie in SQL Server 2008.There is a Proc.In this Proc, I have

  • 0

I am newbie in SQL Server 2008.There is a Proc.In this Proc, I have two select statements.When I execute my Proc, I will get results in two table which I accepted. But I want to this return in single table.

My Proc –

 ALTER PROC [GetPaymentGateway]  
 @CompanyID VARCHAR(3),  
 @ChannelType varchar(15)=null
AS  

IF @ChannelType='BODC' OR @ChannelType='BO-DC'  
BEGIN
    SELECT [card_name], [card_type], [BODC_Amount], [BODC_Amount_Type], PGM.PG_Type FROM credit_card_master CCM
    INNER JOIN PaymentGateway_master PGM
    ON PGM.payment_gateway_code = CCM.payment_gateway_code  
    WHERE CCM.company_id = @CompanyID and CCM.disabled = '1'

    SELECT PGM.Payment_Gateway_Name, PGNBC.BODC_Charge_Amt, PGNBC.BODC_Charge_type, PGM.PG_Type 
    FROM PG_NetBanking_Charges PGNBC
    INNER JOIN PaymentGateway_master PGM
    ON PGM.payment_gateway_code = PGNBC.payment_gateway_code
    WHERE PGNBC.company_id = @CompanyID
END

IF @ChannelType='B2C' OR @ChannelType='ONLINE-DC'  
BEGIN
    SELECT [card_name], [card_type], [charge_amount], [B2C_Amount_type], PGM.PG_Type FROM credit_card_master CCM
    INNER JOIN PaymentGateway_master PGM
    ON PGM.payment_gateway_code = CCM.payment_gateway_code 
    WHERE CCM.company_id = @CompanyID and CCM.disabled = '1' 

    SELECT PGM.Payment_Gateway_Name, PGNBC.Online_DC_Charge_Amt, PGNBC.Online_DC_Charge_type, PGM.PG_Type 
    FROM PG_NetBanking_Charges PGNBC
    INNER JOIN PaymentGateway_master PGM
    ON PGM.payment_gateway_code = PGNBC.payment_gateway_code
    WHERE PGNBC.company_id = @CompanyID
END 

Please suggest me how is it possible??

Thanks in advance.

  • 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-25T12:48:38+00:00Added an answer on May 25, 2026 at 12:48 pm

    To compbine two queries in one table, you need the UNION operation. That takes two result sets, and basically glues them together.
    Union has few restrictions, and the most important is that it’s necessary that the queries have the same number of columns.

    In you queries you have different number of columns selected, the credit_card_master queries have 5 columns each, and the PG_NetBanking_Charges queries have 4 columns each.

    From what I can see, i guess that the card_type column from the first query has no equivalent in the second query, so you could rewrite the second query as:

    SELECT card_name, card_type, charge_amount, B2C_Amount_type, PGM.PG_Type 
      FROM ...
      WHERE ...
    UNION
    SELECT PGM.Payment_Gateway_Name, null, PGNBC.Online_DC_Charge_Amt,
           PGNBC.Online_DC_Charge_type, PGM.PG_Type
      FROM ...
      WHERE ...
    

    Also note that the columns in the result set will take the names of the columns from the first query, so you might want to add a column alias to get a more meaningful / generic name for the column. Also I usually add a “Source” column that enables me to trace the origin of the row in the union, so my final query would look like:

    SELECT 1 as Source, card_name as Name, card_type as Type, 
           charge_amount as Ammount, B2C_Amount_type as AmmountType,
           PGM.PG_Type as PG_Type
      FROM ...
      WHERE ...
    UNION
    SELECT 2, PGM.Payment_Gateway_Name, null, PGNBC.Online_DC_Charge_Amt,
           PGNBC.Online_DC_Charge_type, PGM.PG_Type
      FROM ...
      WHERE ...
    

    and the result will have the columns Source, Name, Type, Ammount, AmmountType and PG_Type, where Source will be 1 for rows from the first, and 2 for rows from the second query.

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

Sidebar

Related Questions

I'm brand new to SQL Server 2008, and have some newbie questions about the
I am newbie in SQL Server 2008.There are three tables which I am using.
Dear All, please help me since I'm newbie in SQL Server. I have a
This is sort of SQL newbie question, I think, but here goes. I have
I am a complete newbie to SSIS. I have a c#/sql server background. I
I’m a newbie in Stored Procedures in SQL Server 2005. Let’s say we have
I am a newbie to SQL server. keeping this question as reference.My doubt is
Firstly I'm a complete newbie when it comes to SQL Server. I have five
Newbie alert! ASP .net | C# | VS2008 | MS SQL server 2008 R2
I am a complete SQL Server newbie but I have experience with Oracle and

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.