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 |
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2012-01-16 : 19:23:38
|
| i have a tabletranid detailkey detailvalue 1 key1 value1 1 key2 value2on a update statement i only want to update 1 detailvalue with a case statementCASE WHEN detailkey = 'key1' THEN newvalue1 endthis updates key1 value but makes key2 value nullhow do you use a case to update the one you want and not touch the other values? |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-16 : 19:31:54
|
Use a where clause like this:UPDATE yourTable SET detailValue = newValueWHERE detailkey = 'key1'; If you must use a case expression, do it like this, where you explicitly tell SQL to leave detailValue alone (i.e., set it to itself) if detailkey is not key1UPDATE yourTable SETdetailValue = CASE WHEN detailkey = 'key1' THEN newvalue1 ELSE detailValue END |
 |
|
|
tpiazza55
Posting Yak Master
162 Posts |
Posted - 2012-01-17 : 12:02:35
|
| thanks |
 |
|
|
|
|
|