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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:38:53+00:00 2026-05-17T16:38:53+00:00

I have two tables with identical structure and VERY LARGE number of fields (about

  • 0

I have two tables with identical structure and VERY LARGE number of fields (about 1000). I need to perform 2 operations
1) Insert from the second table all rows into the fist. Example:

INSERT INTO [1607348182]
SELECT * 
FROM _tmp_1607348182;

2) Update the first table from the second table
but for update i can’t found proper sql syntax for update.

Queries like:

Update [1607348182]
set [1607348182].* = tmp.*
from [1607348182]
inner join _tmp_1607348182 as tmp on tmp.recordid = [1607348182].recordid

or

Update [1607348182]
from [1607348182]
inner join _tmp_1607348182 as tmp on tmp.recordid = [1607348182].recordid

are invalid.

  • 1 1 Answer
  • 1 View
  • 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-17T16:38:53+00:00Added an answer on May 17, 2026 at 4:38 pm

    Not sure if you’ll be able to accomplish this without using dynamic sql to build out the update statement in a variable.

    This statement will return a list of columns based on the table name you put in:

    select name from syscolumns
    where [id] = (select [id] from sysobjects where name = 'tablename')
    

    Not sure if I can avoid a loop here….you’ll need to load the results from above into a cursor and then build a query from it. Psuedo coded:

    set @query = 'update [1607348182] set '
    load cursor --(we will use @name to hold the column name)
    while stillrecordsincursor
    set @query = @query + @name + ' = tmp_[1607348182]. ' +@name + ','
    load next value from cursor
    loop!
    

    When the query is done being built in the loop, use exec sp_executesql @query.

    Just a little warning…building dynamic sql in a loop like this can get a bit confusing. For trouble shooting, putting a select @query in the loop and watch the @query get built.

    edit:
    Not sure if you’ll be able to do all 1000 rows in an update at once…there are logical limits (varchar(8000)?) on the size that @query can grow too. You may have to divide the code so it handles 50 columns at a time. Put the columns from the syscolumns select statement into a temp table with an id and build your dynamic sql so it updates 20 columns (or 50?) at a time.

    Another alternative would be to use excel to mass build this. Do the column select and copy the results into column a of a spreadsheet. Put ‘= in column b, tmp.[12331312] in column c, copy column a into column D, and a comma into column e. Copy the entire spreadsheet into a notepad, and you should have the columns of the update statement built out for you. Not a bad solution if this is a one shot event, not sure if I’d rely on this as a on-going solution.

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

Sidebar

Related Questions

I have two tables that have virtually identical content and very similar structure. They
I have two tables TABLE1 and TABLE2 with identical structures. I need a trigger
I have two identical tables with the same number of rows but with different
I have two tables with identical structure except for one column... Table 2 has
I have two somewhat big (4+ million records) tables with identical structure, and they
I have two tables with identical fields, 35 identical fields. I know I can
Let's say I have two tables with identical structure, call them A & B.
I have two identical (in structure) databases residing on separate backend servers. I need
I have two identical tables and need to copy rows from table to another.
I have two tables with identical fields that share many rows. I'd like to

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.