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 |
|
dgaylor
Yak Posting Veteran
54 Posts |
Posted - 2003-05-08 : 12:19:41
|
| I have two tables.TableA TableB---------------------COL1 COL1COL2 COL2COL3 COL3COL4etc.I want to update COL3 in TableA with the value of COL3 in TableB, joining the 2 table on COL1 and COL2, but if a join can't occur I want to set COL3 to a default value of '9999'. I have tried the following and it doens't work, and I would like to do this in one statement. Is it possible? Thanks.update aset col3 = case when a.col1 = b.col1 and a.col2 = b.col2 then b.col3 else '9999' endfrom tablea a, tableb bThe syntax seems to be accepted but it never finishes.Thanks for any help. |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-05-08 : 12:39:56
|
update tableaset col3 = coalesce(b.col2,'9999')from tablea a left join tableb b on (a.col1=b.col1 and a.col2=b.col2) Jay White{0} |
 |
|
|
dgaylor
Yak Posting Veteran
54 Posts |
Posted - 2003-05-08 : 15:45:14
|
| Thanks, it worked perfectly. |
 |
|
|
|
|
|