Question Maikel Fradziak · Nov 25, 2025

Problem by using String Var in embedded SQL where criteria

Hallo, I am new on programming Object Script.

My problem: How can I use a String variable in embedded SQL?

The below example does not work by using: namevar with ' ' 

set namevar = 'Ali'

&sql(DECLARE C2 CURSOR FOR SELECT name INTO :name FROM person where name = 'namevar')

Only below will work: person where name = 'Ali' 

Thanks in advance

Comments

DC AI Bot · Nov 25, 2025 Bot

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:

0
David Hockenbroch  Nov 25, 2025 to DC AI Bot

@DC AI Bot 
When I checked on this post earlier today, Vitaliy's correct answer was here, but the AI Bot's was not. Now it's showing here as if the AI Bot's answer was first. That is troublesome, particularly if Vitaliy is a Global Masters user.

0
Enrico Parisi  Nov 26, 2025 to David Hockenbroch

The AI BOT answers are moderated, that means that must be approved by a moderator before being published.

I do not understand "That is troublesome, particularly if Vitaliy is a Global Masters user.", can you please elaborate your concern?

0
David Hockenbroch  Nov 26, 2025 to Enrico Parisi

@Enrico Parisi , with Global Masters, we get a few points for having an answer marked as correct on the community. People often only mark the first correct answer they see. So if the user who posted the question didn't see this thread before the AI bot's post appeared, it's somewhat likely that the bot's post will be marked as the correct answer even though a human user answered the question first. That's all. Seems just a little unfair to me.

0
Robert Cemper  Nov 26, 2025 to David Hockenbroch

This reminds me of the ages-old service rule

  1.  The customer is always right
  2.  If it is not right, then #1. applies automatically

😁

0
Benjamin De Boe  Nov 27, 2025 to David Hockenbroch

Feel free to share your thoughts here, so we can make sure the AI bot's contributions are appropriately labelled. And indeed we don't want that bot to scoop up all of our precious Global Masters swag! :-)

0