Published on InterSystems Developer Community (https://community.intersystems.com)

Home > How to use variable in a sql statement with the like operator

Question
Stella Ticker · Apr 29, 2017

How to use variable in a sql statement with the like operator

What is the correct way to write embedded SQL that will use a Like operator and local variable. Ex How can a sql query return the IDs of all rows where LastName has the substring "Doe"?

Set nameToFind="Doe". The below does not work.

&sql(Select ID from myTable where LastName like '%:nameToFind%')

Simple enough but this syntax is tricky!!

#Caché

Source URL:https://community.intersystems.com/post/how-use-variable-sql-statement-operator