• The immediate problem is having PKID set as an IDENTITY. Ditch that and it will run as is.

    PKID INT IDENTITY(1,1) NOT NULL

    Another thing that can cause a problem is the mapping flag for the OPENXML command. You don't specify a value so it defaults to zero and attribute-centric mapping. Fortunately, that is what you are trying to do. But it's better if you specify a value of 1 (a value of 2 is for element-centric mapping...enter a 2 and see what happens):

    ...

    FROM OPENXML(@hdoc,'//row',1) WITH PrintRequestRows

    Final suggestion is to use a TRY/CATCH block for sp_xml_preparedocument. I always declare and build my XML as a string first so I can use various functions for removing excess spaces, invalid characters, etc.

    BEGIN TRY

    EXEC sp_xml_preparedocument @idoc OUTPUT, @strXML

    END TRY

    BEGIN CATCH

    BEGIN

    IF @debug = 1

    BEGIN

    SELECT @strXML AS ModifiedXML

    SELECT CONVERT(XML,@strXML) AS FormattedXML

    END

    SELECT

    'Invalid XML' AS XMLStatus

    RETURN

    END

    END CATCH