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 |
flamz
Starting Member
21 Posts |
Posted - 2008-03-23 : 11:00:26
|
Hi, what is a easy way clamp the result of an operation in a update statement?UPDATE MyTable SET field = CLAMP(someCalculatedValue,0,100) WHERE bla.. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-23 : 12:05:19
|
Try using CASE .. WHEN |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-03-23 : 12:53:44
|
what is clamp?_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-23 : 13:22:49
|
clamp is a function which will cause a value to lie between a min & max value. http://www.codeproject.com/KB/cs/generic_clamp_function.aspxThe equivalent in sql will beUPDATE MyTable SET field = CASE WHEN someCalculatedValue < 0 THEN 0 WHEN someCalculatedValue >100 THEN 100 ELSE someCalculatedValue END |
 |
|
|
|
|