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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Clamp

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
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-03-23 : 12:53:44
what is clamp?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

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.aspx

The equivalent in sql will be
UPDATE MyTable SET field = CASE
WHEN someCalculatedValue < 0 THEN 0
WHEN someCalculatedValue >100 THEN 100
ELSE someCalculatedValue
END
Go to Top of Page
   

- Advertisement -