Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server: A severe error occurred on the current command. The results, if any, should be discarded
    primarykey
    data
    text
    <p>I have the following SQL Server Query in a stored procedure and I am running this service from a windows application. I am populating the temp table variable with 30 million records and then comparing them with previous days records in <code>tbl_ref_test_main</code> to Add add and delete the different records. there is a trigger on <code>tbl_ref_test_main</code> on insert and delete. Trigger write the same record in another table. Because of the comparison of 30 million records its taking ages to produce the result and throws and error saying <code>A severe error occurred on the current command. The results, if any, should be discarded.</code></p> <p>Any suggestions please. </p> <p>Thanks in advance.</p> <pre><code>-- Declare table variable to store the records from CRM database DECLARE @recordsToUpload TABLE(ClassId NVARCHAR(100), Test_OrdID NVARCHAR(100),Test_RefId NVARCHAR(100),RefCode NVARCHAR(100)); -- Populate the temp table INSERT INTO @recordsToUpload SELECT class.classid AS ClassId, class.Test_OrdID AS Test_OrdID , CAST(ref.test_RefId AS VARCHAR(100)) AS Test_RefId, ref.ecr_RefCode AS RefCode FROM Dev_MSCRM.dbo.Class AS class LEFT JOIN Dev_MSCRM.dbo.test_ref_class refClass ON refClass.classid = class.classid LEFT JOIN Dev_MSCRM.dbo.test_ref ref ON refClass.test_RefId = ref.test_RefId WHERE class.StateCode = 0 AND (ref.ecr_RefCode IS NULL OR (ref.statecode = 0 AND LEN(ref.ecr_RefCode )&lt;= 18 )) AND LEN(class.Test_OrdID )= 12 AND ((ref.ecr_RefCode IS NULL AND ref.test_RefId IS NULL) OR (ref.ecr_RefCode IS NOT NULL AND ref.test_RefId IS NOT NULL)); -- Insert new records to Main table INSERT INTO dbo.tbl_ref_test_main Select * from @recordsToUpload EXCEPT SELECT * FROM dbo.tbl_ref_test_main; -- Delete records from main table where similar records does not exist in temp table DELETE P FROM dbo.tbl_ref_test_main AS P WHERE EXISTS (SELECT P.* EXCEPT SELECT * FROM @recordsToUpload); -- Select and return the records to upload SELECT Test_OrdID, CASE WHEN RefCode IS NULL THEN 'NA' ELSE RefCode END, Operation AS 'Operation' FROM tbl_daily_upload_records ORDER BY Test_OrdID, Operation, RefCode; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload