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 2005 Forums
 Transact-SQL (2005)
 How to frame query for following requirement

Author  Topic 

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-01-22 : 08:35:38
Table1
A B 1 2 3
q p a b c
w r e e g

Table2
A B P Q 1 2 3 F
q p e g - - - p
e r g l - - - k

I want to update the columns 1,2,3 in Table2 where
Table1.A = Table2.A and Table1.B = Table2.B

How can we frame query?

G. Satish

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2009-01-22 : 08:38:31
[code]update t2
set [1]=t1.[1],
[2]=t1.[2],
[3]=t1.[3]
from table1 t1 join table2 t2
on t1.A = t2.A and t1.B = t2.B[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-22 : 08:40:29
UPDATE t2
SET t2.[1] = t1.[1], t2.[2] = t1.[2], t2.[3] = t1.[3]
FROM Table2 AS t2
INNER JOIN Table1 AS t1 ON t1.A = t2.A AND t1.B = t2.B



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-01-22 : 09:00:02
Thank You. I thought inner join wont work with update.
quote:
Originally posted by Peso

UPDATE t2
SET t2.[1] = t1.[1], t2.[2] = t1.[2], t2.[3] = t1.[3]
FROM Table2 AS t2
INNER JOIN Table1 AS t1 ON t1.A = t2.A AND t1.B = t2.B



E 12°55'05.63"
N 56°04'39.26"




G. Satish
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-22 : 09:16:00
why didnt you refer to books online to check it? for syntax related queries, books online should be first resort
Go to Top of Page
   

- Advertisement -