See examples and try "Run It" in JSON_ARRAYAGG.

E.g.:

  1. SELECT JSON_ARRAYAGG(Home_StateFROM Sample.Person WHERE Home_State %STARTSWITH 'A'

    Result:

    ["AR","AL","AR","AL","AL","AR","AK","AL","AR","AK","AK","AZ","AR","AR","AL"]
  2. SELECT JSON_OBJECT('state':Home_StateFROM Sample.Person WHERE Home_State %STARTSWITH 'A'

    Result:

    {"state":"AR"}
    {"state":"AL"}
    {"state":"AR"}
    {"state":"AL"}
    {"state":"AL"}
    {"state":"AR"}
    {"state":"AK"}
    {"state":"AL"}
    {"state":"AR"}
    {"state":"AK"}
    {"state":"AK"}
    {"state":"AZ"}
    {"state":"AR"}
    {"state":"AR"}
    {"state":"AL"}
  3. SELECT JSON_ARRAYAGG(JSON_OBJECT('state':Home_State)) FROM Sample.Person WHERE Home_State %STARTSWITH 'A'

    Result:

    [{"state":"AR"},{"state":"AL"},{"state":"AR"},{"state":"AL"},{"state":"AL"},{"state":"AR"},{"state":"AK"},{"state":"AL"},{"state":"AR"},{"state":"AK"},{"state":"AK"},{"state":"AZ"},{"state":"AR"},{"state":"AR"},{"state":"AL"}]

NoContext helped. What does it mean?

NoContext
With the same success it is possible to specify NoContext for the class:

Class Test.String Extends %String [ NoContext ]
{

Method Get() As %String CodeMode = objectgenerator ]
{
  %code.WriteLine("  q $this.Test()")
  q $$$OK
}

}
This works too btw:

It doesn't work for me:

MPP5376 : Method or Property 'Test' does not exist in this class.

You can do it even easier:

&sql(SELECT {fn TIMESTAMPDIFF(SQL_TSI_HOUR,CURRENT_TIMESTAMP(3),:tx)})

Small example:

&sql(SELECT CURRENT_TIMESTAMP(3),
            {fn TIMESTAMPADD(SQL_TSI_MINUTE,67,CURRENT_TIMESTAMP(3))} into :txBefore,:txAfter)
txBefore," -> ",txAfter,!!

&sql(SELECT {fn TIMESTAMPDIFF(SQL_TSI_HOUR,CURRENT_TIMESTAMP(3),:txAfter)},
            {fn TIMESTAMPDIFF(SQL_TSI_HOUR,:txBefore,:txAfter)} into :r1,:r2)
r1,!,r2

Result:

USER>^test
2019-04-08 08:51:34.916 -> 2019-04-08 09:58:34.916
 
1
1
USER>^test
2019-04-08 08:55:11.907 -> 2019-04-08 10:02:11.907
 
2
2

There are two ways to define views, so I'll give you both options:

  1. /// bla-bla-bla:<ul>
    /// <li>Name - Person's name;</li>
    /// <li>SSN - Person's Social Security number. This is validated using pattern match;</li>
    /// <li>DOB - Person's Date of Birth.</li></ul>
    Class view.Person ClassType = view, CompileAfter Sample.PersonDdlAllowedNot ProcedureBlockViewQuery = { select Name,SSN,DOB from Sample.Person} ]
    {
    
    }
  2. /// This sample persistent class represents a person.
    /// <p>Maintenance note: This class is used by some of the bindings samples.
    Class Sample.Person Extends (%Persistent%Populate%XML.Adaptor)
    {
    
    ...
    
    /// bla-bla-bla:<ul>
    /// <li>Name - Person's name;</li>
    /// <li>SSN - Person's Social Security number. This is validated using pattern match;</li>
    /// <li>DOB - Person's Date of Birth.</li></ul>
    Query viewPerson() As %SQLQuery SqlViewSqlViewName viewPerson ]
    {
    select Name,SSN,DOB from Sample.Person
    }
    
    ...
    
    }

Now take a look at these classes from Documatic.

First, I would not use the input values directly in the query text, but would use Input Host Variables
Second, if it is necessary, it is more elegant to use the following syntax:

Set stmt ##CLASS(%SQL.Statement).%New()
Set query $$$FormatText("Select Val1, Val2 FROM Table WHERE Val1=%1",$$$quote("SomeCondition"))
Ideally these should be :
&SQL(SELECT Val1, Val2
INTO :val1, :val2
FROM Table
WHERE Val1='SomeCondition')

This is and now works:

&SQL(SELECT Val1Val2
               INTO :val1:val2
               FROM "Table"
               WHERE "Val1"='SomeCondition')