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

  • Home
  • SEARCH
  • 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 6222335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:17:47+00:00 2026-05-24T08:17:47+00:00

I am trying to come up with an insert sql stament that will insert

  • 0

I am trying to come up with an insert sql stament that will insert data from a table into another existing table. There are in fact some ways of doing this but I did not find a way that matches my requirements.

I need an insert statement type query that will insert data into another table but it does not knows which headers both table have. For instance the origin table has 25 headers and the target one has 20, which 10 of them match in name. I would like to transfer the ones that are matching the name of the headers ignoring the rest.

Hope I was clear and hope anyone will be able to help me

  • 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-24T08:17:48+00:00Added an answer on May 24, 2026 at 8:17 am

    I think you have to get the two tables columns then filter em to get match columns names after that you can build your insert into statement and exec it

    to get columns exists in both table

    Declare @cols varchar(max)
    
    SELECT  @cols =COALESCE(@cols +',','')+'['+COLUMN_NAME+']'
    FROM DbName.INFORMATION_SCHEMA.COLUMNS 
    WHERE TABLE_NAME = N'security' and COLUMN_NAME in( 
          SELECT COLUMN_NAME
          FROM DbName.INFORMATION_SCHEMA.COLUMNS 
          WHERE TABLE_NAME = N'debt_securities')
    

    then create insert statement

    declare @query varchar(max)='insert into debt_securities('+@cols+')
                                 select '+@cols+' from [security]'
    

    then execute it

    exec(@query)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to come up with a search/replace expression that will convert from Oracle
I'm trying to come up with a Java regex that will match a filename
I am trying to script the creation of the INSERT SQL for data in
I am trying to make a method for a class that will automatically insert
I have a table whose data looks like this: INSERT INTO `cm_case_notes` (`id`, `case_id`,
I'm trying to insert some data into a local MySQL database by using MySQL
I am trying to come up with such a solution that the user is
I am trying to come up with the best data structure for use in
I'm trying to use the entity framework to take data (nested relationships) from one
Hello iam trying to store sum information inside a SQL Server table , but

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.