Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xml dml conditional attribute inserting does not work

From: "SammyBar" <sammybar@-----.--->
To: NULL
Date: 7/1/2008 6:10:00 PM

Yes!
That hint is just what I was looking for...

Declare
     @sSerie Varchar(10)
    ,@sFolio Varchar(10)

--Select @sSerie = '123'
Select @sFolio = '456'

Declare @xmlCfd xml
Set @xmlCfd = ''
Set @xmlCfd.modify('
    declare namespace cfd="http://www.sat.gob.mx/cfd/2";
    insert (
        <Comprobante>
        {
            if (sql:variable("@sSerie") != "")
            then attribute serie {sql:variable("@sSerie")}
            else ()
            ,if (sql:variable("@sFolio") != "")
            then attribute folio {sql:variable("@sFolio")}
            else ()
        }
        </Comprobante>
        )
        into (/)[1]'
    )

Select @xmlCfd

"Bob" <Bob@d...> escribió en el mensaje 
news:4E672E09-9EF5-46E7-96F1-A2337B311878@m......
> Got these two to work, but using element:
>
> DECLARE @sSerie VARCHAR(10),
> @sFolio VARCHAR(10)
>
> DECLARE @xmlCfd XML
>
> SET @xmlCfd = ''
> SET @sSerie = 2 -- Or 3
> SET @sFolio = 3
>
> -- Go easy on yourself and check the condition in SQL
> IF @sSerie = 2
> SET @xmlCfd.modify('declare namespace cfd="http://www.sat.gob.mx/cfd/2";
>   insert (<Comprobante>{sql:variable("@sSerie")}</Comprobante>)
>   into (/)[1]')
> ELSE
> SET @xmlCfd.modify('declare namespace cfd="http://www.sat.gob.mx/cfd/2";
>   insert (<Comprobante>{sql:variable("@sFolio")}</Comprobante>)
>   into (/)[1]')
>
> SELECT @xmlCfd
>
> -- Reset
> -- XQuery if method
> SET @xmlCfd = ''
> SET @xmlCfd.modify('declare namespace cfd="http://www.sat.gob.mx/cfd/2";
> insert
> if (sql:variable("@sSerie")="2")
> then element Comprobante {sql:variable("@sSerie")}
> else element Comprobante {sql:variable("@sFolio")}
> into (/)[1]')
>
> SELECT @xmlCfd
>
> This returns:
> <Comprobante>2</Comprobante>
>
> I know you mentioned attributes, but you can't have valid xml with
> attributes but no elements right?
>
> Post your expected results if this doesn't help.
>
> HTH
> wBob
>
> "SammyBar" wrote:
>
>> Hi,
>>
>> I'm experimenting with XML DML. I need to add an attribute only if it 
>> meet
>> some condition. But I can not use an sql variable to implement the
>> condition. The following example gives me an error:
>> XQuery [modify()]: An expression was expected
>>
>> Declare @sSerie Varchar(10)
>>   ,@sFolio Varchar(10)
>>
>> Declare @xmlCfd xml
>> Set @xmlCfd = ''
>> Set @xmlCfd.modify('
>>   declare namespace cfd="http://www.sat.gob.mx/cfd/2";
>>   insert (
>>     <Comprobante>
>>       {
>>         if ({sql:variable("@sSerie")} = 2)
>>         then attribute serie {sql:variable("@sSerie")}
>>         else ()
>>         ,attribute folio {sql:variable("@sFolio")}
>>       }
>>     </Comprobante>
>>   )
>>   into (/)[1]'
>> )
>>
>> Select @xmlCfd
>>
>> Obviously, the condition I need should look like
>> if ({sql:variable("@sSerie")} != '')
>>
>> How to implement such an expression?
>>
>> Any hint is welcomed
>> Thanks in advance
>> Sammy
>>
>>
>> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent