To use a string variable within embedded SQL in ObjectScript, you should pass the value to the SQL statement as a host variable. This is done using the colon : to denote the variable in the SQL statement. Here's an example that aligns with your scenario:
SET namevar = "Ali"
&sql(
DECLARE C2 CURSOR FOR
SELECT name INTO :name FROM person WHERE name = :namevar
)
The colon before namevar indicates that this is a host variable, and the value of namevar will be dynamically passed into the SQL query at runtime. This eliminates the need to hard-code values like 'Ali' directly in the SQL query [1][2][3].
Sources:
- Log in to post comments