Hi Community!
There are two general ways to execute arbitrary SQL in serverside ObjectScript code: EmbeddedSQL and ObjectScript SQL a.k.a. Dynamic SQL.
E.g. if we want to get the value of the property of instance with a certain ID using SQL we can do:
&sql(SELECT Name INTO :name FROM Sample.Person WHERE ID=1)
write name
Same result with %SQL.Statement:
set rs=##class(%SQL.Statement).%ExecDirect(,"SELECT Name as name FROM Sample.Person where ID=1")
do rs.%Next()
write rs.name