xml parsing - Sybase ASE xmltable - pattern not working -


i trying following sybase ase 15.0.2 finding hard through:

the motive extract contents of <tables> tag. me this?

refer - http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc30020.1502/html/xmlb/cfhidcjc.htm

declare @purgetableinfo varchar(16300) select @purgetableinfo =      '<purge>         <start-time>00:00:000</start-time>         <end-time>03:00:000</end-time>         <tables>             <table>                 <table_name>table1</table_name>                 <owner>dbo</owner>                 <columns>                     <column>                         <column_name>column1</column_name>                         <column_value>121212xdfsdsdsdsd</column_value>                         <column_condition>like</column_condition>                     </column>                     <column>                         <column_name>column2</column_name>                         <column_value>121212xdfsdsdsdsd</column_value>                         <column_condition>like</column_condition>                     </column>                 </columns>             </table>         </tables>     </purge>'         select *            xmltable('/purge/tables/table/columns/column'                     passing @purgetableinfo                     columns columnname varchar(255) path 'column_name',                             tablename varchar(255) pattern '../../table_name') purgeinputdetails 

in above question, trying avoid looping , trying use xmltable() query. but, turns out that, xmltable() little rigid more complex structures multiple tables , columns xml (in question, mentioned base case of single table , multiple columns xml). so, going "xmlextract()+looping" way. here solution multiple table/ multiple columns xml:

declare @i int declare @extractedtable varchar(50) declare @j int declare @extractedcolumn varchar(50) select @i = 1 select @extractedtable = ''  while (@extractedtable != null) begin     select @extractedtable=convert(varchar(50),xmlextract ('/purge/tables/table['+convert(varchar(5),@i)+']/table_name/text()', @purgetableinfo))     print "%1!", @extractedtable      if(@extractedtable != null)     begin         select @j = 1         select @extractedcolumn = ''         while (@extractedcolumn != null)         begin             select @extractedcolumn=convert(varchar(50),xmlextract ('/purge/tables/table['+convert(varchar(5),@i)+']/columns/column['+convert(varchar(5),@j)+']/column_name/text()', @purgetableinfo))             print "%1!", @extractedcolumn             if(@extractedcolumn != null)             begin                 insert tabcols select @extractedtable tablename, @extractedcolumn columnname                 select @j = @j+1             end         end         select @i = @i+1     end end commit 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -