title: Getting Check Constraint error when trying to insert into a table
body: <p>We are in the process of putting a partnering site on our ERP system.  They have a notes table that I am trying to move into our notes table by scripting it in T-SQL since there are hundreds of records.  I am using SQL Server 2008R2.  I keep getting an The INSERT statement conflicted with the CHECK constraint "ObjectNotesCk4". The conflict occurred in database "PLT_NAMALT_App", table "dbo.ObjectNotes" error.   </p>
  
  <p>Some details.  Our ObjectNotes table requires the RowPointer from the PO, the PK from the SpecificNotes table and then some additional fields which I'm populating with constants.  So first I capture the RowPointer from the PO table using a cursor, then I insert into the SpecificNotes table matching on PO#  and try to capture the PK using OUTPUT INTO a temp table.  Then I try to insert into the ObjectNotes table using the variable I inserted into in my OUTPUT.  So my query...(just an FYI I am limiting it to one PO#, one line # for verification).</p>
  
  <pre><code>DECLARE @SpecificToken TABLE (SpecificTokenID TokenType, NoteContent OleObjectType, NoteDesc LongDescType)
  
  DECLARE @RowPointer RowPointerType
  
  DECLARE MY_CURSOR CURSOR 
    LOCAL STATIC FOR 
  
  SELECT  RowPointer FROM poitem
  
  OPEN MY_CURSOR
  FETCH NEXT FROM MY_CURSOR INTO @RowPointer 
  
  WHILE @@FETCH_STATUS = 0
  BEGIN 
  INSERT INTO SpecificNotes  (NoteContent, NoteDesc)
          OUTPUT inserted.SpecificNoteToken, inserted.NoteContent, inserted.NoteDesc
          INTO @SpecificToken
      SELECT LongNote, 'Visual Note'
      FROM purc_line_notes vb 
      JOIN  poline slp
      ON vb.PONUM = slp.po_num
      and vb.LINE_NO = po_line
      WHERE slp.po_num = 'P000060883'
      and slp.po_line = '1'
      AND slp.rowpointer = @RowPointer
  
      INSERT INTO ObjectNotes (RefRowPointer,NoteHeaderToken,SpecificNoteToken,NoteType)
      VALUES (@OuterID, 5, (SELECT SpecificTokenID FROM @SpecificToken),0)
  
      FETCH NEXT FROM MY_CURSOR INTO @RowPointer 
  END
  CLOSE MY_CURSOR
  DEALLOCATE MY_CURSOR
  </code></pre>
  
  <p>Also when testing what the values are in @SpecificToken, SpecificNoteToken is 0 but should be 185 (checked the value in the SpecificNotes table)</p>
  
  <p>In SpecificNotes, SpecificNoteToken is the Primary Key, which is why I do my insert into that table first.
  In ObjectNotes, ObjectNoteToken is the Primary Key but SpecificNoteToken is a foreign key.  RefRowPointer is a foreign key to the poline table (slp).</p>
  
  <p>This is my first time using OUTPUT INTO, I'm not sure this is the right way to go since I am reading mixed things about being able to use it with a primary key.  I also apologize for being wordy, I wanted to make sure I described my situation thoroughly.  </p>