Using the COM CRM.CreateQueryObj() to call a Stored Procedure.

Less than one minute read time.

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:

Using Code to Import Data in a on Premise Installation