我有5列如表:賦值給基於其他列在SQL Server 2008中的列更有效的方式值
id value1 value2 value3 Score
1 X X X
2 X Y Z
3 Y Z Z
4 X Z X
我想是分配等於Y和Z最終值(沒有X)像每列:
id value1 value2 value3 final
1 X X X 0
2 X Y Z 2
3 Y Z Z 3
4 X Z X 1
我這樣做的方式是:
Update table
set final = 3
where value1 <> 'X' and value2 <> 'X' and value3 <> 'X'
Update table
set final = 2
where (value1 <> 'X' and value2 <> 'X' and value3 = 'X')
OR (value1 = 'X' and value2 <> 'X' and value3 <> 'X')
OR (value1 <> 'X' and value2 = 'X' and value3 <> 'X')
Update table
set final = 1
where (value1 <> 'X' and value2 = 'X' and value3 = 'X')
OR (value1 = 'X' and value2 <> 'X' and value3 = 'X')
OR (value1 = 'X' and value2 = 'X' and value3 <> 'X')
Update table
set final = 0
where value1 = 'X' and value2 = 'X' and value3 = 'X'
我想問一下我f有沒有比這更聰明/更有效的方法?任何意見,將不勝感激。謝謝!
的應用情況... – Squirrel