Here's another approach that uses save text file, load text file, and evalinsert. With evalinsert you surround your variables with the caret character (^), and it substitutes the currently assigned variable values in to your string.
// Save the query to a file with a placeholder for the identifier
sqlQuery = "Select x from table where identifier = ^primaryidentifier^";
save text file("c:\temp\myquery.sql", sqlquery);
// Load the contents of the text file into a variable
sqlQuery = load text file("c:\temp\myquery.sql");
// Set the identifier using evalinsert
primaryidentifier = "12345";
sql_statement = evalinsert(sqlquery);
print(sql_statement);
"Select x from table where identifier = 12345"