sql server 2008 - Need Single Row Result using openrowset -



sql server 2008 - Need Single Row Result using openrowset -

i have xml having images tag , within there 12 url tag.

i have write query fetch result xml.

hotel.xml file :

<images> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> <url></url> </images>

here code :

create table #workingtable ( info xml ) insert #workingtable select * openrowset(bulk 'd:\hotels.xml', single_blob) info declare @xml xml , @hdoc int select @xml = info #workingtable exec sp_xml_preparedocument @hdoc output, @xml declare @tmp varchar(max) set @tmp = '' select pref.value('(hotel_ref/text())[1]','varchar(400)')as hotel_ref, sref.value('(text())[1]', 'varchar(400)')+ ';' #workingtable cross apply data.nodes('//hotels/hotel') hotel(pref) cross apply pref.nodes('images/url') images(sref) exec sp_xml_removedocument @hdoc drop table #workingtable

my problem is returning 12 rows . need url values comma separated. how possible.

you don't need temp table , don't need calls sp_xml*.

load xml this.

declare @xml xml set @xml = ( select * openrowset(bulk 'd:\hotels.xml', single_blob) info )

the xml have provided poor match query using. here builds comma separated string xml in question.

select ( select ', '+t.n.value('text()[1]', 'varchar(400)') @xml.nodes('images/url') t(n) xml path(''), type ).value('substring(text()[1], 3)', 'varchar(max)')

sql-server-2008 stored-procedures openxml openrowset

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -