Below is some code that illustrates how a Stored Procedure maybe invoked in the QueryObject.
var strSQL = "DECLARE @@ret int";
strSQL += " EXEC @@ret=eware_get_identity_id 'notes'";
strSQL += " INSERT notes";
strSQL += " (note_noteid,note_foreigntableid,note_foreignid,note_note,note_createdby, note_createddate)";
strSQL += " VALUES (@@ret, 5,28,'This is a test',1,getDate())";
var myQuery = CRM.CreateQueryObj(strSQL,"");
myQuery.ExecSQL();
The stored procedure used here is the eware_get_identity_id procedure that is responsible for safely generating the unique ids for records within a SQL Server database. Its usage has been discussed before in this article: