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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:17:48+00:00 2026-06-13T00:17:48+00:00

I have like 10 diff temporary tables created in SQL server, what I am

  • 0

I have like 10 diff temporary tables created in SQL server, what I am looking to do is union them all to a final temporary table holding them all on one table. All the tables have only one row and look pretty much exactly like the two temp tables below.

Here is what I have so far this is an example of just two of the temp tables as their all exactly like this one then #final is the table I want to union the all to:

      create table #lo
      (
         mnbr bigint
      )
      insert into #login (mnbr)
      select distinct (_ID)
      FROM [KDB].[am_LOGS].[dbo].[_LOG] 
      WHERE time >= '2012-7-26 9:00:00

       Select count(*) as countreject
       from #lo

     create table #pffblo
     (
       mber_br
     )
     insert into #pffblo (mber_br)
     select distinct (mber_br)
     from individ ip with (nolock)
     join memb mp with (nolock)
          on( ip.i_id=mp.i_id and mp.p_type=101) 
      where ip.times >= '2012-9-26 11:00:00.000'

     select count(*) as countaccept

    create table #final
    (
        countreject bigint
        , Countacceptbigint
        .....
    )

    insert into #final (Countreject, Countaccept....more rows here...)
    select Countreject, Countaccept, ...more rows selected from temp tables.
    from #final
    union 
    (select * from #lo)
    union
    (select * from #pffblo)
    select *
    from #final

drop table #lo
drop table #pffblo
drop table #final

if this the form to union the rows form those temp tables to this final one. Then is this correct way to show all those rows that were thus unioned. When I do this union I get message number of columns in union need to match number of columns selected in union

  • 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-13T00:17:49+00:00Added an answer on June 13, 2026 at 12:17 am

    I think you’re using a union the wrong way. A union is used when you have to datasets that are the same structure and you want to put them into one dataset.

    e.g.:

    CREATE TABLE #Table1
    (
      col1 BIGINT
    )
    
    CREATE TABLE #Table2
    (
      col1 BIGINT
    )
    
    --populate the temporary tables
    
    CREATE TABLE #Final
    (
      col1 BIGINT
    )
    
    INSERT INTO #Final (col1)
    SELECT *
    FROM #Table1
    UNION
    SELECT *
    FROM #Table2
    
    drop table #table1
    drop table #table2
    drop table #Final
    

    I think what you’re trying to do is get 1 data set with the count of all your tables in it. Union won’t do this.

    The easiest way (although not very performant) would be to do select statements like the following:

    CREATE TABLE #Table1
    (
      col1 BIGINT
    )
    
    CREATE TABLE #Table2
    (
      col1 BIGINT
    )
    
    --populate the temporary tables
    
    CREATE TABLE #Final
    (
      col1 BIGINT,
      col2 BIGINT
    )
    
    
    
    
    INSERT INTO #Final (col1, col2)
    select (SELECT Count(*) FROM #Table1) as a, (SELECT Count(*) FROM #Table2) as b
    
    select * From #Final
    
    drop table #table1
    drop table #table2
    drop table #Final
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two properties files that contain information. I would like to diff them
I have a rather large diff of 2 GIT branches and would like to
I have a little problem where I would like to insert a svn diff
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
I have tried like this <script type=text/javascript> var date2=02/09/2009; var date1=03/12/2009; var diff =
I have two different files in different branches. How can I diff them in
I have the data in table like below: **start_date** **end_date** --------------- ----------------- 2011-06-27 13:24:45.137417
I have a table with column 'size' that has file sizes in diff units
I have table structure like below: events (boxing, sparring etc) competitors (users who are
I have a table like this: rowInt Value 2 23 3 45 17 10

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.