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 |
|
midan1
Starting Member
39 Posts |
Posted - 2008-06-29 : 03:37:25
|
i need help create an update based on difference between two fields can you help me to build an update based on difference between two fields i use only the numbers 1,2,3,4so the difference can be only with this numbers can bee only 1 between 4 OR 0like if the difference between two fields +1 than add 1if the difference between two fields +2 than add 2if the difference between two fields -2 than add 2........................UPDATE tabledeclare @new_unitset @new_unit--- the user want to write the value he need (only between 1 and 4 )SET unit =--- CASE +WHEN (@new_unit-unit)= -1THEN unit -1CASEWHEN (@new_unit-unit)= +1THEN unit +1WHEN (@new_unit-unit)= +2THEN unit +2WHEN (@new_unit-unit)= +3THEN unit +3WHEN (@new_unit-unit)= +4THEN unit +4--- CASE -WHEN (@new_unit-unit)= -1THEN unit -1WHEN (@new_unit-unit)= -2THEN unit -2WHEN (@new_unit-unit)= +3THEN unit -3WHEN (@new_unit-unit)= -4THEN unit -4--- CASE =0WHEN (@new_unit-unit)= 0THEN unit=unitEND END TNX |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-29 : 05:11:13
|
declare @new_unitset @new_unit=value--user input value (1,2,3,4)UPDATE tableSET unit =unit + (@new_unit-unit) |
 |
|
|
|
|
|