• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Move between tables

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
johnkainn
Asked:
johnkainn
5 Solutions
 
rajvjaCommented:
insert into table2(t2.text)
select table1.text from table1
0
 
Pratima PharandeCommented:

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

  I hope IDs are IDENTITY columns
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RiteshShahCommented:
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
 
RiteshShahCommented:
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
 
RiteshShahCommented:
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
 
waltersnowslinarnoldCommented:
Try the following..,

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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now