Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to copy from one table to another using joins

Author  Topic 

threeonethree
Starting Member

2 Posts

Posted - 2010-09-28 : 09:47:11
i have two tables named tcl and circuits in mssql ..

table named tcl with serial as primary key

tcl
-----------------------------
serial popn backboneissue
1 abc ----
2 xyz ----
3 abc ----
n xyz ----
--------------------------------

table named circuits with popname as primary key

circuits
----------------------
popname issuedetail

abc text for abc
xyz text for xyz


how do i copy text in circuits.issuedetail to tcl.backboneissue where circuits.popname and tcl.popn match?

the resulting table tcl should look like

tcl
------------------------------
serial popn backboneissue
1 abc text for abc
2 xyz text for xyz
3 abc text for abc
n xyz text for xyz

please help

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2010-09-28 : 09:55:09
update t
set backboneissue = c.issuedetail
from tcl t join circuits c on t.popn = c.popname

Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

threeonethree
Starting Member

2 Posts

Posted - 2010-09-28 : 12:23:38
i used this query on 2 small tables that i created and it worked great. but then i imported large tables from excel to microsoft sql 2005 and when i use this query it says 0 rows affected..


what could be the problem ? could it be the datatypes cudnt be compared?

the query im using now is

update tcl set backboneissues = backbone.issue from tcl join backbone on tcl.pop=backbone.pop;

please help me troubleshoot this..
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-28 : 15:28:54
could it be the datatypes cudnt be compared?
How can we know that? We don't know anything about your tables.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2010-09-28 : 15:39:27
And if they are the same, you obviously don't have any matches where tcl.pop=backbone.pop

Terry

-- You can't be late until you show up.
Go to Top of Page
   

- Advertisement -