Skip to content
Advertisement

The mutator ‘modify ()’ of ‘@Mydoc’ can not be called with a NULL value

declare @Mydoc xml,@tagcomplemento = '</complemento>';
select @Mydoc=
SELECT Impuesto as 'TotalImpuestoTrasladados',
            (SELECT Importe,TasaCuota AS 'TasaOCuota',TipoFactor,Impuesto
            FROM CDFIDet
            FOR XML RAW('cfdi_trasladado'),type,root('cfdi_traslado'))
    FROM CDFIDet
    FOR XML RAW('cfdi_impuestos'),type
select @Mydoc;
SET @Mydoc.modify('
    insert sql:variable("@tagcomplemento")
    into (/cfdi_comprobante)[1]');

I have a stored procedure with the query above. When I execute it, it returns…

Mens 5302, Level 16, State 1, Procedure usp_CFDI_Save2XML, Line 49
The mutator ‘modify ()’ of ‘@Mydoc’ can not be called with a NULL value.

What am I doing wrong? Please note, when I execute the query separately it works as expected, but with the store procedure not.

Advertisement

Answer

You can set @Mydoc like this.

select @Mydoc= (
SELECT Impuesto as 'TotalImpuestoTrasladados',
            (SELECT Importe,TasaCuota AS 'TasaOCuota',TipoFactor,Impuesto
            FROM CDFIDet
            FOR XML RAW('cfdi_trasladado'),type,root('cfdi_traslado'))
    FROM CDFIDet
    FOR XML RAW('cfdi_impuestos'),type )
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement