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 |
|
miked1978
Starting Member
25 Posts |
Posted - 2009-01-27 : 09:28:10
|
| I have a table (named History_Act) that has Date1, Division, History, and Actuals as columns. I want to create another column that takes the greater value of History or Actuals.Example:Date1 Division History Actual NewColumn1/1/08 pipe 251 185 2511/3/08 pipe 252 259 259What would my script look like to do this? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-27 : 09:33:41
|
| [code]UPDATE tSET t.NewColumn=tmp.ValFROM Table tINNER JOIN (SELECT Date.MAX(Val) AS Val FROM ( SELECT Date1 AS Date,History AS Val FROM Table UNION ALL SELECT Date1,Actual FROM Table1 )r GROUP BY Date )tmpON tmp.Date=t.Date1[/code] |
 |
|
|
|
|
|