on 2010 Aug 16 2:41 PM
If the executing event is the only instance of this event, what will be the value of NumActive will it be 0 (excluding the current instance) or 1 (including the current instance)?
By the way I have seen code like this:
IF CAST( event_parameter('NumActive' ) AS INTEGER ) > 1 THEN RETURN;
Is it necessary to cast the value?
Request clarification before answering.
The value will be '1' in this case. The event_parameter function always returns a string, so you need to cast it when comparing with an integer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Martin: In your proposed statement the numeric 1 will be automatically cast to the string '1' and if EVENT_PARAMETER('NumActive') returns '1' then you will end up with the behaviour that you wanted.
There is a small correction to the above. The comparison domain between a string and any exact numeric is NUMERIC (see a slightly dated whitepaper I wrote for version 9.0):
2.6 Comparisons Between Strings and Exact Numerics
When comparing an exact numeric value to a string value (either a char or binary type), the comparison data type is numeric.
Given this, technically the CAST to integer is not required because the same semantics are used without the cast. However, mixed domain comparisons are subtle and is a best practice to use CAST to make the code clearer.
There is a further consideration when using a cast in that it constrains the string to really be an integer an not NUMERIC value:
select * from T where '1.1' = 1 -- A - no rows
select * from T where cast('1.1' as int) = 1 -- B - error
I'm forced to join in Breck's sigh: "If Ivan had a blog..." - cf. http://sqlanywhere.blogspot.com/2009_04_01_archive.html.
User | Count |
---|---|
60 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.