Advertisement

07.23.2008 at 11:13AM PDT, ID: 23589555 | Points: 500
[x]
Attachment Details

Copy a data from one table to another using SQL query

Asked by netformx in SQL Query Syntax, SQL Server 2005, Microsoft Development

Tags: SQL

I have to identical (same structure) SQL 2000 tables in two different databases. I need to copy a data from one table to another.

Source Table:
ID                            Name                                                   Descr     Enabled
0                              D_1                                                                        1
1                              D_2                                                                        1
2                              D _3                                                                       1
3                              D _4                                                                       1
4                              SomeName                                                       0

Target Table:
ID                            Name                  Descr     Enabled
0                              C_1        -                              0
1                              C_2        -                              0
2                              C_3        -                              0
3                              C_4        -                              0
4                              C_5        -                              0
5                              C_6      -                                 1

Desired result (after copy of source to target):
ID                            Name                                                   Descr     Enabled
0                              D_1                                                                        1
1                              D_2                                                                        1
2                              D _3                                                                       1
3                              D _4                                                                       1
4                              SomeName                                                       0
5                              C_6      -                                                                 1

I tried the following query:
Update targetDB.dbo.TargetTable
Set targetDB.dbo.TargetTable.Name= sourceDB.dbo.sourceTable.Name
From sourceDB.dbo.sourceTable
Where sourceDB.dbo.sourceTable.ID= targetDB.dbo.sourceTable.ID

But I got an error:
Subquery returned more than 1 value. &

Any ideas how it can be done?

Start Free Trial
[+][-]07.23.2008 at 11:18AM PDT, ID: 22072198

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:19AM PDT, ID: 22072213

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:20AM PDT, ID: 22072228

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 11:25AM PDT, ID: 22072294

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628