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 |
|
nvakeel
Yak Posting Veteran
52 Posts |
Posted - 2008-03-17 : 16:38:28
|
| Here I get a problem in updating a table.CREATE TABLE #TMP1(NUM INT, VAL VARCHAR(5)) INSERT INTO #TMP1SELECT 1,2UNIONSELECT 2,3UNIONSELECT 3,NULLUNION SELECT 4,5UPDATE #TMP1SET VAL = CASE WHEN NUM = 3THEN (SELECT SUM(CAST(VAL AS INT) ) FROM #TMP1)ENDSELECT * FROM #TMP1(4 row(s) affected)Warning: Null value is eliminated by an aggregate or other SET operation.(4 row(s) affected)NUM VAL----------- -----1 NULL2 NULL3 104 NULL(4 row(s) affected)Here I lost the values in "VAL" while doing SUM operatin which i should not.can anyone help me |
|
|
tm
Posting Yak Master
160 Posts |
Posted - 2008-03-17 : 16:51:24
|
| Update statement should be:UPDATE #TMP1SET VAL = CASE WHEN NUM = 3THEN (SELECT SUM(CAST(VAL AS INT) ) FROM #TMP1)ELSE VAL -- << Add ELSE VALEND |
 |
|
|
nvakeel
Yak Posting Veteran
52 Posts |
Posted - 2008-03-18 : 08:13:04
|
| thnkss |
 |
|
|
|
|
|