I have some xml data stored in an XML Column in a table in sql server 2005.
Record1 would have data for that column would look like this:
<ArrayOfThings xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SomeCompany">
<Things>
<Thing>
<Name>Monkey</Name>
</Thing>
<Thing>
<Name>Lion</Name>
</Thing>
<Thing>
<Name>Shoe</Name>
</Thing>
</Things>
</ArrayOfThings>
Record 2 might have data like this for that column
<ArrayOfThings xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SomeCompany">
<Things>
<Thing>
<Name>Monkey</Name>
</Thing>
<Thing>
<Name>Elephant</Name>
</Thing>
<Thing>
<Name>Hammer</Name>
</Thing>
<Thing>
<Name>Bucket</Name>
</Thing>
</Things>
</ArrayOfThings>
Can anyone help me with what the syntax would look like to select distinct things from this table.
The results returned would look like this: Monkey Lion Shoe Elephant Hammer Bucket
obviously this is not production data :)
Setup script:
CREATE TABLE [SomeSchema].[MyTable](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ThingData] [xml] NULL,
CONSTRAINT [PK_Party] PRIMARY KEY CLUSTERED
(
[Id] ASC
)
) ON [PRIMARY]
GO
INSERT INTO [SomeSchema].[MyTable]
([ThingData])
VALUES
(
'<ArrayOfThings xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SomeCompany">
<Things>
<Thing>
<Name>Monkey</Name>
</Thing>
<Thing>
<Name>Lion</Name>
</Thing>
<Thing>
<Name>Shoe</Name>
</Thing>
</Things>
</ArrayOfThings>
')
GO
INSERT INTO [SomeSchema].[MyTable]
([ThingData])
VALUES
(
'<ArrayOfThings xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SomeCompany">
<Things>
<Thing>
<Name>Monkey</Name>
</Thing>
<Thing>
<Name>Elephant</Name>
</Thing>
<Thing>
<Name>Hammer</Name>
</Thing>
<Thing>
<Name>Bucket</Name>
</Thing>
</Things>
</ArrayOfThings>
')
GO
And the select would go against the column in the table