Open topic with navigation

TIBCO BusinessEvents® Enterprise Edition 6.3.1

# Bind Variables in Query Text

Query definitions can use literal values for entity attributes in query text, or they can use bind variables whose values are provided at runtime.

In the `Query.create()` function, use a dollar sign ($) to indicate a bind variable in the query text. (See `$min` in the following example.)

The values for all bind variables must be supplied to a statement when it executes. Set the value of a bind variable, using the `Query.Statement.setVar()` function, from the CEP Query Functions catalog, as shown next.

    Query.Statement.setVar(String StatementName, String BindVariableName, Object value);

When you use the `Query.Statement.setVar()` function, functions must be called in the following order:

- `Query.Statement.open()`
- `Query.Statement.setVar()`
- `Query.Statement.execute()` OR `Query.Statement.executeWithCallback()` OR `Query.Statement.executeWithBatchCallback()`

All functions must reference the same query statement name.

Note: Bind variables cannot be used with the `like` operator.

Bind variables cannot be used with the `from` clause. However see Using Strings (Instead of Variables) in From Clauses for an alternative.

The following example shows how a bind variable in a query definition is set as the value of an event property by the `Query.Statement.setVar()` function. The value could be defined as a literal value as desired, or in some other way, depending on context and need.

For example:

    Query.create("report927", "select agent_name, total_sales, zipcode from /Concepts/Sales where total_sales >= $min");
    Query.Statement.open("report927", S_Id);
    Query.Statement.setVar(S_Id, "min", evt.min_total_sales);
    Query.Statement.execute(S_Id, "rset");

Where `evt.``min_total_sales` is an event property of a numeric type.

## Clearing Bind Variables

You can use `Query.Statement.clearVars()` to clear all bind variable values associated with the named statement.

Subtopics

Did you find this helpful?

YesNo
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO BusinessEvents® Enterprise Edition

Copyright © 2004-2024. Cloud Software Group, Inc. All Rights Reserved.