Home All Groups Group Topic Archive Search About

how sql xml query to get empty element tag

Author
28 Nov 2006 9:41 PM
martin1
Hi, All,

I want to generate empty data tag, for example, the table1 has 2 fileds
called field1 and field2, the field1 has data there but field2 no data, when
creating xml fiel using query:

select field1, field2 from table1 for xml auto, elements

it creates xml file without empty elment tag like this:

<Table1>
<field1> 23 <field1>
</Table1>

But I want field2 xml tag <field2 /> show in the file like

<Table1>
<field1> 23 <field1>
<field2 />
</Table1>

That means <field2 /> tell no data, but I want the xml tag display in the
file.
can anyone know how to generate empty data xml tag using above sql xml query
or another solution?

Thanks in advance
Martin

Author
13 Dec 2006 6:02 PM
DanielReis
The problem is the NULL values of the fields.
You should update first the null Values to ‘’ for example:
<<<
UPDATE DETALHES
SET TEXTO = ''
WHERE TEXTO IS NULL
>>>
and then your query will result!

DanyR



Show quoteHide quote
"martin1" wrote:

> Hi, All,
>
> I want to generate empty data tag, for example, the table1 has 2 fileds
> called field1 and field2, the field1 has data there but field2 no data, when
> creating xml fiel using query:
>
>  select field1, field2 from table1 for xml auto, elements
>
>  it creates xml file without empty elment tag like this:
>
> <Table1>
> <field1> 23 <field1>
> </Table1>
>
> But I want field2 xml tag <field2 /> show in the file like
>
> <Table1>
> <field1> 23 <field1>
> <field2 />
> </Table1>
>
> That means <field2 /> tell no data, but I want the xml tag display in the
> file.
> can anyone know how to generate empty data xml tag using above sql xml query
> or another solution?
>
> Thanks in advance
> Martin
>