title: Invalid cursor state
body: <p>We have triggers on a table called OSPP to save specific data to a table for later use.
  I get the following error in SAP when adding more than one line at a time to the table.</p>
  
  <p><strong>Invalid Cursor State</strong></p>
  
  <p>We have SQL Server 2005 SP3 (but I tried it on a clean 2005 install, on SP1 and SP2)</p>
  
  <p>The one trigger : </p>
  
  <pre><code>CREATE TRIGGER [dbo].[tr_OSPP_Insert]
     ON  [dbo].[OSPP]
     FOR INSERT
  AS 
  BEGIN
      Declare @ItemCode varchar(255)
      Declare @CardCode varchar(255)
      Declare @Price decimal(18,2)
      Declare @ListNum bigint 
      Declare @ID bigint
      Declare @Remote char(1)
  
  
      DECLARE db_cursor CURSOR FOR 
      SELECT ItemCode, CardCode, Price, ListNum
      FROM INSERTED
  
      OPEN db_cursor  
      FETCH NEXT
      FROM db_cursor  INTO @ItemCode, @CardCode, @Price, @ListNum
      WHILE @@FETCH_STATUS = 0
      BEGIN
  
      SELECT @Remote = isnull(U_Remote, 'N') FROM OITM WHERE ItemCode = @ItemCode
  
          IF ltrim(rtrim(upper(@Remote))) = 'Y'
          BEGIN
  
          SELECT @ID = U_ID FROM [dbo].[@BDS_MAINTENANCE]
          UPDATE [dbo].[@BDS_MAINTENANCE] set U_ID = U_ID + 1
  
          INSERT INTO [dbo].[@BDS_REMOTESPECIALPRICELIST]
          (   
              Code,
              [Name],
              U_ID,
              U_ItemCode,
              U_CardCode,
              U_Price,
              U_ListNum,
              U_TransactionType,
              U_Uploaded
          ) VALUES (
              @ID,
              '_' + cast(@ID as VARCHAR(50)),
              @ID,
              @ItemCode,
              @CardCode,
              @Price,
              @ListNum,
              1,
              0
          )
  
  
      FETCH NEXT
      FROM db_cursor INTO @ItemCode, @CardCode, @Price, @ListNum
      END
  
      CLOSE db_cursor  
      DEALLOCATE db_cursor
  
  
  END
  
  END
  </code></pre>
  
  <p>We also tried :</p>
  
  <pre><code>CREATE TRIGGER [dbo].[tr_OSPP_Insert]
     ON  [dbo].[OSPP]
     FOR INSERT
  AS 
  BEGIN
  
      SELECT * INTO [@TEMPTABLE222] FROM INSERTED 
  
  END
  </code></pre>
  
  <p>But still get the same error.</p>
  
  <p>Do you guys have any idea what is wrong?</p>
  
  <p>Thanks in advance!</p>