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 |
|
sql777
Constraint Violating Yak Guru
314 Posts |
Posted - 2008-01-14 : 11:00:43
|
| Hi,I have a int field in my table names Count.In my sproc, I am updating this field by subtracting 1 from it, but I am fearing that I might get into a situation where I am subtracting 1 from a value of 0.intField = intField - 1Will ISNULL prevent intField from going below 0?So:intField = ISNULL(intField - 1, 0) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-14 : 11:03:50
|
No.An INT column can store values ranging from -2147483648 to 2147483647.UPDATE Table1SET Col1 = Col1 - 1WHERE Col1 > 0 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2008-01-14 : 16:11:15
|
| in case intField = 1, (intField - 1) is 0 and not NULLso ISNULL function wont work here |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-15 : 03:08:10
|
intField = ISNULL(NULLIF(intField, 0) - 1, intField) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-16 : 01:50:30
|
quote: Originally posted by rohitkumar in case intField = 1, (intField - 1) is 0 and not NULLso ISNULL function wont work here
OP didnt specify that. He/She wants to avoid having negative numbersMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|