?
Solved

Move between tables

Posted on 2010-01-11
7
Medium Priority
?
182 Views
Last Modified: 2012-05-08
I have 2 tables:
Table1   T1Id, T1Text
Table2   T2Id, T2Text
I would like to create a new row in Table2 for each row in Table1 and set Table2.T2Text=Table1.T1Text.
How is best to do that?

0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Assisted Solution

by:rajvja
rajvja earned 160 total points
ID: 26282333
insert into table2(t2.text)
select table1.text from table1
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 80 total points
ID: 26282339

Insert into Table2   ( T2Id, T2Text)
Select T1Id, T1Text From Table1
0
 
LVL 11

Assisted Solution

by:rajvja
rajvja earned 160 total points
ID: 26282345
Hi,

  I hope IDs are IDENTITY columns
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 31

Accepted Solution

by:
RiteshShah earned 680 total points
ID: 26282351
is this one time process or something?

You can do something like this.



insert into table2 (t2id,t2text)
Select t1.t1id, t1.t1text from table1 as t1  where t1.t1id not in (select t2.t2id from table2)

Open in new window

0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 26282356
options given above my first comment may help you in first time but whenever you will run query next time, duplicate records start comming.
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 26282364
with the help of following script, you can update your table2.



update t2
set t2.t2text=t1.t1text
from table1 as t1 join table2 as t2 on t1.t1id=t2.t2id where t2.t2text<>t1.t1text

Open in new window

0
 
LVL 7

Assisted Solution

by:waltersnowslinarnold
waltersnowslinarnold earned 80 total points
ID: 26282390
Try the following..,

Insert into Table2 (T2Id, T2Text) Select T1Id, T1Text From Table1
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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