Solved

Merging two one to one tables

Posted on 2013-06-30
1
261 Views
Last Modified: 2013-06-30
I have two tables with a one to one relationship.


As an example:

ClientTable
clientId
startdate
firstname
lastname

ClientInfoTable
ClientInfoId
ClientId
address1
address2
city
state
zip
phone


I want to add the fields from the second table into the first table. I can add the empty fields. But I need to know, once I've added the fields, is there a way to run a query that will import that data from table2 into table1's fields? Then I can delete table2.

I know I can do this with a loop one row at a time, but I'm wondering if there is some kind of update query that will do them all at once with the query?

thanks!
0
Comment
Question by:Starr Duskk
1 Comment
 
LVL 2

Accepted Solution

by:
Starr Duskk earned 0 total points
ID: 39288544
I figured it out, something like this, but with all the fields needed.

MERGE Client AS cli
 USING (SELECT clientid,WorkPhone FROM clientInformation) AS ci
ON cli.clientid = ci.clientid
 WHEN MATCHED THEN UPDATE SET cli.WorkPhone = ci.WorkPhone
 ;

thanks!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question