Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.

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?

asked 16 Aug '10, 13:41

Martin's gravatar image

accept rate: 14%

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.

permanent link

answered 16 Aug '10, 15:04

Bruce%20Hay's gravatar image

Bruce Hay
accept rate: 48%

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

(16 Aug '10, 15:26) Martin

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

(16 Aug '10, 16:17) Mark Culp

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
(02 Apr '11, 15:29) Ivan T. Bowman
Replies hidden
Comment Text Removed

I'm forced to join in Breck's sigh: "If Ivan had a blog..." - cf.

(04 Apr '11, 03:18) Volker Barth
Comment Text Removed
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 16 Aug '10, 13:41

question was seen: 2,433 times

last updated: 04 Apr '11, 03:19