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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:10:29+00:00 2026-05-21T14:10:29+00:00

So I am not even sure if this is possible but it really would

  • 0

So I am not even sure if this is possible but it really would be awesome to learn and to be able to do this.

What I am trying to do is run 3 seperate queries that return a single row of data and create a single table that can then be used in a gridview in asp.net

query 1

SELECT     dbo.BOOKINGS.USERID, SUM(dbo.BOOKINGS.APRICE) AS total, COUNT
(dbo.BOOKINGS.USERID) AS bookingcount
FROM         dbo.BOOKINGS INNER JOIN
             dbo.TOURS ON dbo.BOOKINGS.TOUR = dbo.TOURS.TOUR INNER JOIN
             dbo.MAJOR ON dbo.TOURS.MAJOR = dbo.MAJOR.MAJOR
WHERE     (dbo.BOOKINGS.BOOKED BETWEEN CONVERT(int, @startdate) AND CONVERT(int, 
@enddate)) AND (dbo.MAJOR.SDESCR = 'Cruises') AND 
                      (dbo.BOOKINGS.USERID = @USER) AND (dbo.MAJOR.DIVISION = 'A')
GROUP BY dbo.BOOKINGS.USERID

query 2

SELECT     dbo.BOOKINGS.USERID, SUM(dbo.BOOKINGS.APRICE) AS total, COUNT
    (dbo.BOOKINGS.USERID) AS bookingcount
FROM         dbo.BOOKINGS INNER JOIN
                      dbo.TOURS ON dbo.BOOKINGS.TOUR = dbo.TOURS.TOUR INNER JOIN
                      dbo.MAJOR ON dbo.TOURS.MAJOR = dbo.MAJOR.MAJOR
WHERE     (dbo.BOOKINGS.BOOKED BETWEEN CONVERT(int, @startdate) AND CONVERT(int, 
    @enddate)) AND (dbo.MAJOR.SDESCR <> 'Cruises') AND 
                      (dbo.BOOKINGS.USERID = @USER) AND (dbo.MAJOR.DIVISION = 'A')
GROUP BY dbo.BOOKINGS.USERID

query 3

SELECT     SUM(dbo.SUBS.AMOUNT) AS total, COUNT(dbo.SUBS.AMOUNT) AS Memberships, 
    dbo.HOMES.USERID
FROM         dbo.HOMES INNER JOIN
                      dbo.SUBS ON dbo.HOMES.HOME = dbo.SUBS.HOME AND dbo.HOMES.JOINED 
    = dbo.SUBS.PAIDON
WHERE     (dbo.HOMES.JOINED BETWEEN CONVERT(int, @startdate) AND CONVERT(int, 
    @enddate)) AND (dbo.HOMES.USERID = 
    @USER)
GROUP BY dbo.HOMES.USERID

all thre queries return a single row with 3 columns
so i figure this could work the only other difficult part is i want to add a new column

query1 userid  total1   bookingcount
query2 userid  total2   bookingcount
query3 userid  total3   memberships
  • 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-21T14:10:29+00:00Added an answer on May 21, 2026 at 2:10 pm

    You can do this using a UNION statement, all you have to do is get the 3 select statements to return the same amount of fields and in the same order

    SELECT     'QUERY1' AS QUERYNAME, dbo.BOOKINGS.USERID, SUM(dbo.BOOKINGS.APRICE) AS total, COUNT(dbo.BOOKINGS.USERID) AS TOTAL2
    FROM         dbo.BOOKINGS INNER JOIN
                 dbo.TOURS ON dbo.BOOKINGS.TOUR = dbo.TOURS.TOUR INNER JOIN
                 dbo.MAJOR ON dbo.TOURS.MAJOR = dbo.MAJOR.MAJOR
    WHERE     (dbo.BOOKINGS.BOOKED BETWEEN CONVERT(int, @startdate) AND CONVERT(int, 
    @enddate)) AND (dbo.MAJOR.SDESCR = 'Cruises') AND 
                          (dbo.BOOKINGS.USERID = @USER) AND (dbo.MAJOR.DIVISION = 'A')
    GROUP BY dbo.BOOKINGS.USERID
    
    UNION ALL
    
    SELECT     'QUERY2' AS QUERYNAME, dbo.BOOKINGS.USERID, SUM(dbo.BOOKINGS.APRICE) AS total, COUNT(dbo.BOOKINGS.USERID) AS TOTAL2
    FROM         dbo.BOOKINGS INNER JOIN
                          dbo.TOURS ON dbo.BOOKINGS.TOUR = dbo.TOURS.TOUR INNER JOIN
                          dbo.MAJOR ON dbo.TOURS.MAJOR = dbo.MAJOR.MAJOR
    WHERE     (dbo.BOOKINGS.BOOKED BETWEEN CONVERT(int, @startdate) AND CONVERT(int, 
        @enddate)) AND (dbo.MAJOR.SDESCR <> 'Cruises') AND 
                          (dbo.BOOKINGS.USERID = @USER) AND (dbo.MAJOR.DIVISION = 'A')
    GROUP BY dbo.BOOKINGS.USERID
    
    UNION ALL
    
    SELECT         'QUERY3' AS QUERYNAME, dbo.HOMES.USERID, SUM(dbo.SUBS.AMOUNT) AS total, COUNT(dbo.SUBS.AMOUNT) AS TOTAL2
    FROM         dbo.HOMES INNER JOIN
                          dbo.SUBS ON dbo.HOMES.HOME = dbo.SUBS.HOME AND dbo.HOMES.JOINED 
        = dbo.SUBS.PAIDON
    WHERE     (dbo.HOMES.JOINED BETWEEN CONVERT(int, @startdate) AND CONVERT(int, 
        @enddate)) AND (dbo.HOMES.USERID = 
        @USER)
    GROUP BY dbo.HOMES.USERID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure if this is even possible but here goes: Currently I have
I'm not sure if this even exists or not, so I figured I would
I'm not even sure if it's possible but say I have some XML: <source>
currently, I am looking deeper into testing techniques, even though I am not sure
I want to write Html format, but I can not even get a simple
I would like to stop images from loading, as in not even get a
OK, this is an odd request, and it might not even be fully true...
In how many languages is Null not equal to anything not even Null?
I work on Linux all the time and I'm clueless about Windows, not even
I can't seem to get it to work. Perhaps I'm not even testing it

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.