Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - xml dml conditional attribute inserting does not work >Thread Next - Re: xml dml conditional attribute inserting does not work RE: xml dml conditional attribute inserting does not workTo: NULL Date: 7/1/2008 1:47:00 PM
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
>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
