sql select specific text from column

I am trying to select just the "Value" in the column.

Column name is ResultParmsXML. Below is an example of data returned.
<Params><Param Name="The stuck resource" Value="SERVER01" /><Param Name="The stuck resource" Value="SERVER04" /><Param Name="The stuck resource" Value="SERVER06" /><Param Name="The stuck resource" Value="SERVER03" /><Param Name="The stuck resource" Value="SERVER02" /></Params>

here is what i have so far but only returns the first instance of the Value. As you can see above there could be multiple instances.
SELECT SUBSTRING(ResultParamsXML, PATINDEX('%Value=%',ResultParamsXML) +7, 12)
  FROM Test_ResultsLog
  where TestId=1000231
  and ResultCode=1
  order by RunTime desc

I am looking for results like this:
ResultParmsXML
WMVPDAXAPP02, WMVPDAXAPP04,WMVPDAXAPP05
WMVPDAXAPP01,WMVPDAXAPP02,WMVPDAXAPP03
Jacob LepleyBusiness Systems Programming AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
Try it like this:
SELECT  T.C.value('@Value', 'varchar(50)') Value
FROM    Test_ResultsLog
        CROSS APPLY ResultsParamsXml.nodes('Params/Param') T (C)
WHERE   TestId = 1000231
        AND ResultCode = 1
ORDER BY RunTime DESC

Open in new window

0
Anthony PerkinsCommented:
This is how I tested it:
DECLARE @Test_ResultsLog table (TestId integer, ResultCode bit, RunTime integer, ResultsParamsXml xml)
INSERT @Test_ResultsLog(TestId, ResultCode, RunTime, ResultsParamsXml)
VALUES (1000231, 1, 2, '<Params><Param Name="The stuck resource" Value="SERVER01" /><Param Name="The stuck resource" Value="SERVER04" /><Param Name="The stuck resource" Value="SERVER06" /><Param Name="The stuck resource" Value="SERVER03" /><Param Name="The stuck resource" Value="SERVER02" /></Params>')

SELECT  T.C.value('@Value', 'varchar(50)') Value
FROM    @Test_ResultsLog
        CROSS APPLY ResultsParamsXml.nodes('Params/Param') T (C)
WHERE   TestId = 1000231
        AND ResultCode = 1
ORDER BY RunTime DESC

Open in new window

And this is the output:
SERVER01
SERVER04
SERVER06
SERVER03
SERVER02
0
Chris LuttrellSenior Database ArchitectCommented:
Ah, Anthony beat me to the main query that works if you can make your column XML in the first place.
If not and you have to start with an VARCHAR(MAX) or equivalent column you can structure a query like this ( I just wrapped the base table in a nested query casting the Varchar into an XML)
SELECT c.query('.') AS XMLFragment, c.value('(@Value)', 'varchar(40)') AS yourValue
  FROM (SELECT TestId, ResultCode, RunTime, CAST(ResultParamsXML AS XML) ResultParamsXML FROM Test_ResultsLog) x
  CROSS APPLY ResultParamsXML.nodes('/Params/Param') AS t(c)
  where TestId=1000231
  and ResultCode=1
  order by RunTime DESC

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacob LepleyBusiness Systems Programming AnalystAuthor Commented:
The column type was not xml so i had to use this one. I have no idea what is going on in this query but it got the results i was looking for.

Thank you both for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.