Monday 15 February 2010

sql server 2008 - OPENROWSET file with parameters into sql -



sql server 2008 - OPENROWSET file with parameters into sql -

i'm using sql server 2008 , i'm reading file next query:

declare @x xml; set @x = ( select * openrowset(bulk n'c:\attachments\arch.xml', single_blob) [document] ); ;with xmlnamespaces ( 'http://www.sat.gob.mx/timbrefiscaldigital' timbre, 'http://www.sat.gob.mx/cfd/3' cfdi) select timbreuuid = timbre.value('@uuid', 'varchar(100)') @x.nodes('/cfdi:comprobante/cfdi:complemento/timbre:timbrefiscaldigital') a(timbre)

this query gets field called uuid, here good, need instead openrowset (bulk 'string', single_blob) utilize string utilize parameter.

how openrowset utilize parameter?

for example:

declare @param varchar(max)='c:\attachments\arch.xml' set @x = ( select * openrowset(bulk @param, single_blob) [document] );

sorry, have restrictions on network, can not utilize editor properly

i solved problem next code:

declare @path nvarchar(max)=('c:\eme870831t20.xml') declare @results table (x xml) declare @sql nvarchar(max)=n'select cast(replace(cast(x varchar(max)), ''encoding="utf-16"'', ''encoding="utf-8"'') xml) openrowset(bulk '''+@path+''', single_blob) t(x)' insert @results exec (@sql) ;with xmlnamespaces('http://www.sat.gob.mx/cfd/3' cfdi,'http://www.sat.gob.mx/timbrefiscaldigital' tfd) select xmldata.value('(@uuid)', 'varchar(100)') item_id @results cross apply x.nodes('/cfdi:comprobante/cfdi:complemento/tfd:timbrefiscaldigital') a(xmldata);

sql sql-server-2008

No comments:

Post a Comment