Methods: The Query, Value, and Exist

i am reading about XML, but i do not understand, this part
The Query, Value, and Exist Methods: Bind relational columns and variables
Who is Participating?
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.

jorge_torizResearch & Development ManagerCommented:
SET @Doc = '
      <category id="1" name="category 1">
            <product id="1" name="product 1" />
            <product id="2" name="product 2" />
            <product id="3" name="product 3" />
            <product id="4" name="product 4" />
      <category id="2" name="category 2">
            <product id="5" name="product 5" />
            <product id="6" name="product 6" />
            <product id="7" name="product 7" />
            <product id="8" name="product 8" />

--Get the products of category 1
SELECT @Doc.query('/store/category[@id="1"]/product')

--Value method requires a single token, then if we use [1] we are selecting the "TOP 1" elements
SELECT @Doc.value('(/store/category/product[@id="4"]/@name)[1]', 'VARCHAR(15)')

--Exist verify if the result has elements
SELECT @Doc.exist('/store/category[@id="3"]')

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
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

From novice to tech pro — start learning today.