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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 update from 1 table to another

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-05-25 : 06:58:09
i have 2 table 1 with an identity column and toher columns too.
the second with 2 columns of data that i use to find the exact ro with data to update it with the first table.
so how can i take the detiales from table 2 and update them into the field of table 1 wit ha single UPDATE command?
thnaksi n advance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-25 : 07:09:12
General Approach

Update T1
set col=T2.col
from Table1 T1 inner join Table2 T2
on T1.id=T2.id


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-05-25 : 07:34:12
the proble is that i dont have "on T1.id=T2.id"
but rather have " where t2.col1=13 and t2.datatype=29 "


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-25 : 07:35:25
Then how do you match the records with table1?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-05-25 : 08:41:37
that the point i cant using inner joing or something like that
beacuse forom the second table i have unique values for the row i need
and all is left is to update the fildes from table to to 1

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-25 : 08:56:53
pelegk2

Its very hard to understand what u need!!

The answer given to u (by Madhi) is generic, because of the description of the question is so vague. Even ur next answer doesn't make much sense.

U may need to tell how the 2 tables are related. (without any relationship, u won't be able to match records in 2 tables).

Or give some sample data and expected results after updating.
(Also please take some time in typing, to have less typo errors - so that v have to concentrate on SQL only )


Srinika
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-25 : 21:18:55
did you know you can add a where clause on the update statement?

the join fields are the ones that you need to identify which equals to your table1 and table2
otherwise, play around with this...
quote:
from bol
UPDATE titles
SET price = price * 2
WHERE pub_id IN
(SELECT pub_id
FROM publishers
WHERE pub_name = 'New Moon Books')




--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -