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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:06:15+00:00 2026-05-19T02:06:15+00:00

I have two stored procedures for instanse test1 and test2 and both use the

  • 0

I have two stored procedures for instanse test1 and test2 and both use the same parameter X.

X is part of an if statement in both these stored procedures, basically it tells the the procedure which select statement to pick. (this shouldn’t matter as it’s a parameter but i’m not sure)

I want test1 and test2 to be joined by column name, as they will both have the column name, and i want them linked side by side not one underneath the other, is this possible and how

Basically, i want to join these 2 stored procedures in another stored procedure that my asp.net program will call.

this is stored procedure (sp_current)

@mode varchar(20)




AS
SET NOCOUNT ON

Declare @Booked Int
Set @Booked = CONVERT(int,DateAdd(year,  (year( getdate() )) - Year(getdate() + 1),                   
                DateAdd(day, DateDiff(day, 1, getdate()), 1) ) )

 If @mode = 'Sales'
      Select
           Division,
           SDESCR,
           DYYYY,

       Sum(Case When Booked <= @Booked Then NetAmount End) currentNetSales,       
       Sum(Case When Booked <= @Booked Then PARTY End) AS currentPAX        



      From   dbo.B101BookingsDetails
      Where  DYYYY = (year( getdate() ))
      Group By SDESCR, DYYYY, Division           
      Order By Division, SDESCR, DYYYY

else if @mode = 'netsales'

Select Division, 
       SDESCR,        
       DYYYY,  


       Sum(Case When Booked <= @Booked Then NetAmount End) currentNetSales,        


       Sum(Case When Booked <= @Booked Then PARTY End) AS currentPAX      



From   dbo.B101BookingsDetails 
Where  DYYYY = (year( getdate() ))
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'Inssales'

Select Division, 
       SDESCR,        
       DYYYY,  

       Sum(Case When Booked <= @Booked Then InsAmount End) currentInsSales,        

       Sum(Case When Booked <= @Booked Then PARTY End) AS currentPAX        

From   dbo.B101BookingsDetails 
Where  DYYYY = (year( getdate() ))
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'CXsales'
Select Division, 
       SDESCR,        
       DYYYY,  

       Sum(Case When Booked <= @Booked Then CancelRevenue End) currentCXSales,        


       Sum(Case When Booked <= @Booked Then PARTY End) AS currentPAX        


From   dbo.B101BookingsDetails 
Where  DYYYY = (year( getdate() ))
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'othersales'
Select Division, 
       SDESCR,        
       DYYYY,  

   Sum(Case When Booked <= @Booked Then OtherAmount End) currentOtherSales,        
       Sum(Case When Booked <= @Booked Then PARTY End) AS currentPAX        



From   dbo.B101BookingsDetails 
Where  DYYYY = (year( getdate() ))
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'cxvalue'
Select Division, 
       SDESCR,        
       DYYYY,  

       Sum(Case When Booked <= @Booked Then CXVALUE End) currentCXValue,
       Sum(Case When Booked <= @Booked Then PARTY End) AS currentPAX        



From   dbo.B101BookingsDetails 
Where  DYYYY = (year( getdate() ))
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

and
This is sp_compare

@mode varchar(20),
@YearToGet int



AS
SET NOCOUNT ON

Declare @Booked Int
Set @Booked = CONVERT(int,DateAdd(year, @YearToGet - Year(getdate() + 1),                   
                DateAdd(day, DateDiff(day, 1, getdate()), 1) ) )

 If @mode = 'Sales'
      Select
           Division,
           SDESCR,
           DYYYY,

       Sum(Case When Booked <= @Booked Then NetAmount End) ASofNetSales,        
       SUM(NetAmount) AS YENetSales,

       Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX,        
       SUM(PARTY) AS YEPAX


      From   dbo.B101BookingsDetails
      Where  DYYYY = @YearToGet
      Group By SDESCR, DYYYY, Division           
      Order By Division, SDESCR, DYYYY

else if @mode = 'netsales'

Select Division, 
       SDESCR,        
       DYYYY,  


       Sum(Case When Booked <= @Booked Then NetAmount End) ASofNetSales,        
       SUM(NetAmount) AS YENetSales,

       Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX,        
       SUM(PARTY) AS YEPAX


From   dbo.B101BookingsDetails 
Where  DYYYY = @YearToGet
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'Inssales'

Select Division, 
       SDESCR,        
       DYYYY,  

      Sum(Case When Booked <= @Booked Then InsAmount End) ASofInsSales,        
       SUM(InsAmount)  AS YEInsSales, 

       Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX,        
       SUM(PARTY) AS YEPAX

From   dbo.B101BookingsDetails 
Where  DYYYY = @YearToGet
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'CXsales'
Select Division, 
       SDESCR,        
       DYYYY,  

      Sum(Case When Booked <= @Booked Then CancelRevenue End) ASofCXSales,        
       SUM(CancelRevenue) AS YECXSales, 


       Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX,        
       SUM(PARTY) AS YEPAX

From   dbo.B101BookingsDetails 
Where  DYYYY = @YearToGet
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'othersales'
Select Division, 
       SDESCR,        
       DYYYY,  

   Sum(Case When Booked <= @Booked Then OtherAmount End) ASofOtherSales,        
       SUM(OtherAmount) AS YEOtherSales,

       Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX,        
       SUM(PARTY) AS YEPAX


From   dbo.B101BookingsDetails 
Where  DYYYY = @YearToGet
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

Else if @mode = 'cxvalue'
Select Division, 
       SDESCR,        
       DYYYY,  

       Sum(Case When Booked <= @Booked Then CXVALUE End) ASofCXValue,
       SUM(CXVALUE) AS YECXValue,


       Sum(Case When Booked <= @Booked Then PARTY End) AS ASofPAX,        
       SUM(PARTY) AS YEPAX


From   dbo.B101BookingsDetails 
Where  DYYYY = @YearToGet
Group By SDESCR, DYYYY, Division
Order By Division, SDESCR, DYYYY 

I either want to make it one procedure or somehow join them side by side in a seperate procedure

  • 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-19T02:06:15+00:00Added an answer on May 19, 2026 at 2:06 am

    Your question is a bit vage. I guess that both procedures returna result set and you want to return a join of those result sets.

    You can define temporary tables or table variables and use

    INSERT INTO table_1 exec sp_1 ...
    INSERT INTO table_2 exec sp_2 ...
    

    Than you can select from a join from those 2 temporary objects.

    EDIT:
    Not knowing the data-types let me try something like

    create table #tmp1 (
      Division varchar(50),
      SDESCR varchar850),
      DYYYY varchar(5),
      currentNetSales money,
      currentPax money
    )
    
    create table #tmp2 (
      Division varchar(50),
      SDESCR varchar(50),
      DYYYY varchar(5),
      ASofNetSales money,        
      YENetSales money,
      ASofPAX money,        
      YEPAX money
    )
    
     INSERT INTO #tmp1 exec sp_current ('Sales')
     INSERT INTO #tmp2 exec sp_compare ('Sales', 2009)
    
    select t1.Division,
     isnull(t1.SDESCR, t2.SDESCR) SDESCR,
     isnull(t1.DYYYY, t2.DYYYY) DYYYY,
     t1.currentNetSales,
     t1.currentPax,
     t2.ASofNetSales money,        
     t2.YENetSales money,
     t2.ASofPAX money,        
     t2.YEPAX money
    from #tmp1 t1
      full outer join #tmp2 t2 on t1.Division = t2.Division and t1.SDESCR = t2.SDESCR
     Order By Division, SDESCR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two related classes which share a common interface and are both stored
If I have two trivial stored procedures, created like so: create procedure root as
I have a stored procedure that returns two int Values. The first can not
We use stored procedures exclusively here, and that raises a little problem. We cross
I have two tables, one stores the products and quantity we have bought, the
I have two models: Person and Relation. The second one stores information about relations
I have two applications written in Java that communicate with each other using XML
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two elements: <input a> <input b onclick=...> When b is clicked, I

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.