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 |
|
shenacat
Starting Member
3 Posts |
Posted - 2011-06-10 : 19:37:28
|
| Hi---I'm a newbie, just learning the syntax ... want to know how to do something I'm hoping is fairly rudimentary in Management Express for 2008. I've got two tables, TableA & TableB. Trying to update a value in TableA to a set number (3.5) based on a value in TableB. Basically, the IDs match ... so if TableA.id = TableB.id I want to set TableA.weight=3.5.I can't get the syntax right... something likeUPDATE [db].[ob].[tableA] SET weight=3.5 WHEN ...There's where I go wrong. I can't list stuff like [db].[blah].[table].[column] because it errors. I can't just do tableA.column either.so I can't just say:When TableA.col = TableB.col because it errors. Doesn't know what I'm referring to.Help!THANKS! |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-10 : 19:38:35
|
| you want to use WHERE not WHENIf you don't have the passion to help people, you have no passion |
 |
|
|
shenacat
Starting Member
3 Posts |
Posted - 2011-06-10 : 20:05:22
|
| sorry I mistyped, yes WHERE... that was just a typo :)THANKS! |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-06-10 : 21:11:17
|
| [code]UPDATE tgt SET tgt.weight=3.5FROM [db].[ob].[tableA] tgtinner join tablebON tgt.id = TableB.id[/code]make sure to test first on copy table and/or dev databaseIf you don't have the passion to help people, you have no passion |
 |
|
|
shenacat
Starting Member
3 Posts |
Posted - 2011-06-12 : 19:59:34
|
| Thank you so much for your help yosiasz. Your example helped me figure out just what to do! :)THANKS! |
 |
|
|
|
|
|