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.
| Author |
Topic |
|
cqldba303
Starting Member
16 Posts |
Posted - 2012-02-28 : 12:04:22
|
| I have two tables: table1 and table2I have following columns in table1: id,nameI have following columns in table2:p_key,descI need to update table1 based on condition from both table1 and table2.How should i do this?for example I wanted to do:update table1 set id=1 where table2.desc='solution' but this update statement is giving me error?what should be correct statement? |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-02-28 : 12:42:36
|
what's the relationship between the tables?Generally you issue a statement like thisUPDATE t1 SET [ID] = 1FROM table1 AS t1 JOIN table2 AS t2 ON t2.<COLUMN> = t1.<COLUMN>WHERE t2.[desc] = 'solution' Basically -- write a SELECT statement to verify that the rows are correct, then just change the SELECT part to an UPDATE.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-28 : 12:45:13
|
quote: Originally posted by cqldba303 I have two tables: table1 and table2I have following columns in table1: id,nameI have following columns in table2:p_key,descI need to update table1 based on condition from both table1 and table2.How should i do this?for example I wanted to do:update table1 set id=1 where table2.desc='solution' but this update statement is giving me error?what should be correct statement?
so are you basically stating that there's no relationship between tables?your above update doesnt make much senseyou would be better off explaining with some data what exactly you're looking at------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|