You need to do something like this:
SELECT
t.ID, -- or whatever you need from the table where the XML is located
tbl.People.query('AdditionalInfoList')
FROM
dbo.YourTable t
CROSS APPLY
t.(xmlcolumn).nodes('/People') AS Tbl(People)
WHERE
tbl.People.value('(Item[@Name="Info"]/@Value)[1]', 'varchar(50)') LIKE '%Software Development%'
OR
tbl.People.value('(Item[@Name="Title"]/@Value)[1]', 'varchar(50)') LIKE '%Software Engineer%'
That should give you all the entries you're interested in.
Explanations:
The CROSS APPLY
creates a "dummy" table which you need to give a name to - here: Tbl(People)
. What that name is doesn't really matter, and it's not case sensitive, so Tbl
and tbl
are identical.
If you want to Guid and the type as separate values from the <AdditionalInfoList>
, you need to use this query here:
SELECT
t.ID,
--tbl.People.value('(Item[@Name="Info"]/@Value)[1]', 'varchar(50)') AS 'Info',
--tbl.People.value('(Item[@Name="Title"]/@Value)[1]', 'varchar(50)') AS 'Title'
Adtl.Info.value('(@Guid)[1]', 'varchar(50)') AS 'GUID',
Adtl.Info.value('(@type)[1]', 'varchar(50)') AS 'Type'
FROM
@table t
CROSS APPLY
t.xmlcolumn.nodes('/People') AS Tbl(People)
CROSS APPLY
Tbl.People.nodes('AdditionalInfoList/AdditionalInfoListItem') AS Adtl(Info)
WHERE
Tbl.People.value('(Item[@Name="Info"]/@Value)[1]', 'varchar(50)') LIKE '%Software Development%'
OR
Tbl.People.value('(Item[@Name="Title"]/@Value)[1]', 'varchar(50)') LIKE '%Software Engineer%'
You basically have to do a second CROSS APPLY (that'll hurt your performance!) to get the "additional info" list for each of the entries from Tbl.Person
and extract the Guid and the type value from that.
Check out the SQL Server 2005 XQuery and XML DML introduction - about in the middle of the article, there's a section on how to use the .nodes()
function. Very helpful!