Cannot use double quotes ("") within any SQL statement.
Set stmt = ##CLASS(%SQL.Statement).%New() Set query = "Select Val1, Val2 FROM Table WHERE Val1=""SomeCondition""" set tStatus = stmt .%Prepare(query)
Set stmt = ##CLASS(%SQL.Statement).%New() Set query = "Select Val1, Val2 FROM Table WHERE Val1='SomeCondition'" set tStatus = stmt .%Prepare(query)
On next code, the use of delimited identifiers causes the condition to error because you cannot use a double quote in SQL.
&SQL(SELECT Val1, Val2
INTO :val1, :val2
FROM Table
WHERE Val1="SomeCondition")
&SQL(SELECT Val1, Val2
INTO :val1, :val2
FROM Table
WHERE Val1='SomeCondition')
There exists an additional case in which double quotes are allowed but coding guide lines dismmiss its usage in favour to single quotes, as shown below.
Query Example() As %SQLQuery(CONTAINID = 1, ROWSPEC = "ID,Corporation:%Integer,IDNumber:%Integer,Name:%String, DisplayName:%String")
{
SELECT ID, Corporation->CorporationID, IDNumber, Name, (IDNumber || " - " || Name) As
FROM General.Contacts
ORDER BY Name
}
Query Example() As %SQLQuery(CONTAINID = 1, ROWSPEC = "ID,Corporation:%Integer,IDNumber:%Integer,Name:%String, DisplayName:%String")
{
SELECT ID, Corporation->CorporationID, IDNumber, Name, (IDNumber || ' - ' || Name) As
FROM General.Contacts
ORDER BY Name
}