How To Do Dynamic Parsing Node In This Example In Sql?
how to do dynamic parsing node in this example in sql? declare @htmlXML as xml = N'
Solution 1:
You could insert records with 1 select into a table variable, or a temporary table.
declare@VarTabletable (id intidentity(1,1) primary key, [Title] varchar(max), [URL Local] varchar(max), [URL Site] varchar(max));
insertinto@VarTable ([Title], [URL Local], [URL Site])
SELECT
t.v.query('div[@class="widget_fcats_title"][1]').value('.','nvarchar(max)') as [Title],
t.v.query('div[@class="widget_fcats_title"][1]').value('div[1]/a[1]/@href','nvarchar(max)') as [URL Local],
t.v.query('div[@class="widget_fcats_title"][1]').value('div[1]/a[1]/@tppabs','nvarchar(max)') as [URL Site]
FROM@htmlXML.nodes('//div[@class="widget_fcats_box clearfix"]') as t(v);
Then select the things you need from it.
For example:
declare@nodenumberstable (num intprimary key);
insertinto@nodenumbers (num) values (2),(3),(5),(8),(12),(19),(21);
select Title, [URL Local], [URL Site] from@VarTablewhere id in (select num from@nodenumbers);
or:
select Title, [URL Local], [URL Site] from@VarTablewhere [URL Local] like'%-notebook-%';
As a sidenote. It's actually possible to use xquery to only return a specific number of node positions. Won't help in this case though, since nodes() is strict about wanting a literal. For example:
FROM @htmlXML.nodes('//div[@class="widget_fcats_box clearfix"][position() = (2,3,5,8,12,19,21)]') ast(v);
Post a Comment for "How To Do Dynamic Parsing Node In This Example In Sql?"