dbTalk Databases Forums  

FOR XML PATH and empty list

microsoft.public.sqlserver.xml microsoft.public.sqlserver.xml


Discuss FOR XML PATH and empty list in the microsoft.public.sqlserver.xml forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Martin Honnen
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 06:22 AM






Miroo wrote:

Quote:
I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?
Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your
table(s) you want to query.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #12  
Old   
Martin Honnen
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 06:22 AM






Miroo wrote:

Quote:
I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?
Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your
table(s) you want to query.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #13  
Old   
Martin Honnen
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 06:22 AM



Miroo wrote:

Quote:
I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?
Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your
table(s) you want to query.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #14  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
  #15  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
  #16  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
  #17  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
  #18  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
  #19  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
  #20  
Old   
Miroo
 
Posts: n/a

Default Re: FOR XML PATH and empty list - 12-15-2008 , 08:19 AM



Uzytkownik "Martin Honnen" <mahotrash (AT) yahoo (DOT) de> napisal w wiadomosci
news:ex0YMicrosoftqXJHA.556 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
Quote:
Miroo wrote:

I'm simply listing records from a database into such xml:
LIST
ITEM id=1" /
ITEM id=2" /
...
/LIST

I was using FOR XML EXPLICIT for that but now I'd like to do it
using more friendly FOR XML PATH mode. The problem is that if there is
no records in the list it returns empty XML. In FOR XML EXPLICIT mode
it returned empty element.
LIST /

How to achieve it in FOR XML PATH mode?

Does

FOR XML PATH, ROOT('LIST')

do what you want? If not then you need to tell us more about your table(s)
you want to query.
If I do what you suggest I get completely empty XML when there is no
records returned, I need to get empty list element <LIST />

Finally I found out how to do it, and it is pretty simple:
select ( SELECT [@id]=myid from mytable for xml path ('ITEM'), type )
for XML PATH ('LIST')

--
Regards
Miroo



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.