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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:22:51+00:00 2026-06-10T11:22:51+00:00

I have a table T1(col1, col2, info), col1 is primary key. Now I have

  • 0

I have a table T1(col1, col2, info), col1 is primary key. Now I have a another table T2 (col1, col2, col3), col1 is primary key. For example,

T1:

col1 col2 info
num1 data1 info1
num2 data2 info2

T2

col1 col2 col3
num1 data1 Y
num2 data2 N
num3 data3 NULL

How do I write a script to update T1 with T2? The result should be
T1:

col1 col2 col3 info
num1 data1 Y info1
num2 data2 N info2
num3 data3 NULL NULL

Also, if my T2 is not a table, is a excel file instead, is it possible to write a script to import the data to T1 and update T1 at the same time?

  • 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-10T11:22:53+00:00Added an answer on June 10, 2026 at 11:22 am

    It would be easier to add col3 manually to T1. The update script is a two-parter: an Update and an Insert

    UPDATE T1
    SET
      T1.col3 = T2.col3  
    FROM T1 INNER JOIN T2 ON T1.col1 = T2.col1;
    
    INSERT INTO T1
      (col1, col2, col3, info)
      SELECT T2.col1, T2.col2, T2.col3, NULL 
      FROM T2
      WHERE NOT T2.col1 IN (SELECT col1 FROM T1);
    

    In order for T2 to be an Excel file, you would need to set T2 up as an OLEDB table (using a Linked Server and a MS Jet driver).

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

Sidebar

Related Questions

I have a table that has columns like this for example: id,col1,col2,col3,col4 Now, I
I am using SQL SERVER 2005. I have a table table1(ID,col1,col2,col3,col4); Now I have
Now i have a table with 4 columns as below seq col1 col2 col3
I have a table like Table1: col1 col2 col3 and have an index over
I have a table like below: COL1 | COL2 | COL3 ______________________ ITEM1 |
Assume I have the following style table, col1 col2 and col3 have same value
I have a table with columns say col1, col2, col3 . The table has
I have a table with four Columns: Col1, Col2, Col3, and Col4. Col1, Col2,
I have a table which looks like Col1 col2 col3 col4 col5 1 5
I have a table which looks like Col1 col2 col3 col4 col5 1 5

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.