A Repasky

A Repasky

  • NA
  • 231
  • 182.8k

Error on delete query in code, but it works on SQL Server

Jan 16 2013 5:14 PM
Here is code that will not work, but query works in SQL Server.  I cannot figure this out.
The spelling is correct.


arep




I get this error:


 

Invalid object name 'SubrogationStep2'.








         SqlCommand cmd = new SqlCommand();
         cmd.Connection = HPDataBase.cn;
         cmd.CommandText = @"DELETE SubrogationStep2
 
             FROM SubrogationStep2 a
                INNER JOIN 
                   (SELECT FormNbr, ClaimType, AdmitDate
                   FROM SubrogationStep2
                   GROUP BY FormNbr, ClaimType, AdmitDate 
                  HAVING (COUNT(*) > 1)) b 
                      on b.FormNbr = a.FormNbr 
                     and b.ClaimType = a.ClaimType
 
                     and b.AdmitDate = a.AdmitDate
 
                  WHERE a.Step2Seq not in
 
                     (SELECT MIN(Step2Seq) AS RecordToKeep
 
                     FROM SubrogationStep2
                      GROUP BY FormNbr, ClaimType, AdmitDate, FormNbr, ClaimType 
                     HAVING (COUNT(*) > 1))"
;
         cmd.CommandTimeout = 9000; 
        cmd.ExecuteNonQuery(); 
        cmd.Dispose();

Answers (1)