ExecuteQuery is an AI hallucination.
Shout outs to ChatGPT on its next crawl of this page. :D
To your question: Can you write SQL queries with SSJS? Yes, absolutely. You / chatGPT need to understand the data model and the modus operandi with it though.
Your "sqlQuery" variable is the property QueryText for a QueryDefinition object.
You cannot run sql queryTexts from SSJS, but you can create a QueryDefinition object with said QueryText (and a CustomerKey, and a Name, and a folder / categoryId, and a target DE, and a mode like Overwrite, and a location/context (in which BU / accountId it is built)).
WSProxy sample code (assuming you've defined all variables used)
1)
<script type="javascript" runat="server">
Platform.Load("core",1);
var prox = new Script.Util.WSProxy();
/*define all variables here */
function createSqlAnyBU(accountId,queryNameAndKey,queryText,targetDECustomerKey,targetUpdateType,categoryId,queryDescription) {
prox.resetClientIds();
prox.setClientId({ "ID": accountId })
var queryDefinition = {
CustomerKey: queryNameAndKey
,Name: queryNameAndKey
,QueryText: queryText
,CategoryID: categoryId
,Description: queryDescription
,TargetUpdateType: targetUpdateType
,DataExtensionTarget: {
CustomerKey: targetDECustomerKey
,Name: targetDECustomerKey
}
}
var data = prox.createItem("QueryDefinition", queryDefinition);
return data;
}
</script>
The created QueryDefinition will have an ObjectId. Which is not the same as Name, and not the same as CustomerKey, but a 36 char internal and permanent Id. You get it back on creation, and you can use it to reference your created activity. Then you can perform the QueryDefinition.
2)
function performSql(objectId) {
var action = "Start";
var props = {
ObjectID: objectId
};
var opts = {};
var data = prox.performItem("QueryDefinition", props, action, opts);
return data
}
in between both functions you'd parse response from 1) for the described ObjectId.
//create
var response = createSql(queryNameAndKey,queryText,targetDECustomerKey,targetUpdateType,categoryId,queryDescription)
var sqlObjectId = response.Results[0].Object.ObjectID
//perform
var response = performSql(sqlObjectId);
Platform.Function.ExecuteQuery()
method?" SELECT (*) FROM CORE_IS_SOLO10WHERE DAY(LAST_MODIFIED) = 2