cancel
Showing results for 
Search instead for 
Did you mean: 

EVENT_PARAMETER('NumActive')

MCMartin
Participant
2,601

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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

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.

MCMartin
Participant
0 Kudos

so coding it like this will fail?: IF EVENT_PARAMETER( 'NumActive' ) = 1 THEN

MarkCulp
Participant

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

Former Member

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
VolkerBarth
Contributor
0 Kudos

I'm forced to join in Breck's sigh: "If Ivan had a blog..." - cf. http://sqlanywhere.blogspot.com/2009_04_01_archive.html.

Answers (0)