The params argument of the queryExecute() function can be passed in a number of forms. Using an object or a structure will allow named query parameters, while the array method necessitates the question mark (?) placeholders.
Because of this difference, the SQL variable has been defined twice, once in each manner. The query is run and the result is dumped in the final example.
Because of this difference, the SQL variable has been defined twice, once in each manner. The query is run and the result is dumped in the final example.
Object and structure methods
// Params definition option 1.
var sqlParams =
{
firstParam: "FIELD VALUE",
secondParam: "FIELD VALUE"
}
// Params definition option 2.
var sqlParams = structNew();
sqlParams.firstParam = "FIELD VALUE";
sqlParams.secondParam = "FIELD VALUE";
// Params definition option 3.
var sqlParams = structNew();
sqlParams["firstParam"] = "FIELD VALUE";
sqlParams["secondParam"] = "FIELD VALUE";
var sql = "
declare @returnValue nvarchar(255)
exec storedProcedure
@firstField=:firstParam,
@secondField=:secondParam,
@returnThis=@returnValue output
select @returnValue as returnValue";
Array method
// Params definition option 4.
// (Requires the use of question mark parameter placeholders.)
var sqlParams = ["FIELD VALUE", "FIELD VALUE"];
// Params definition option 5.
// (Requires the use of question mark parameter placeholders.)
var sqlParams = arrayNew(1);
arrayAppend(sqlParams, "FIELD VALUE");
arrayAppend(sqlParams, "FIELD VALUE");
var sql = "
declare @returnValue nvarchar(255)
exec storedProcedure
@firstField=?,
@secondField=?,
@returnThis=@returnValue output
select @returnValue as returnValue";
Run and dump query
var example = queryExecute(sql, sqlParams);
dump(example);
Comments
Post a Comment