March 18, 2011 at 1:51 pm
Hi,
Is it possible to use an xml index as a join condition?
For example, want to do something like the following scenario:
create table MyPaths (id int identity(1,1) primary key, path xml);
create primary xml index ix_pxml on MyPaths (path) ;
create xml index ix_xml_path on MyPaths (path) using xml index ix_pxml ;
create table MyNodes (nodeid int primary key, .....)
select a.*, b.*
from MyPaths a
join MyNodes b on path.exist ('/Path/Node[.=' + b.nodeid + ']') = 1
Or something like that.
Thanks in advance,
David
March 18, 2011 at 2:17 pm
You can use an XQuery statement in a join, or a Where clause, but not in that manner. If you try, you'll get an error about "exist" needing a string literal.
You can't construct the XQuery pieces dynamically at runtime, unless you do so via dynamic SQL.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply