Read typed XML in SQL Server 2008

So far, I have written few articles on XML topic, before we move further, I would like to summarize those here with the respected links so if anybody interested, can have look at it.

Apart from above four XML article, today I would like to introduce, how you can read typed XML in Microsoft SQL Server 2008.

I have one very small example to share with you. Have a look.

SET @MyXml =  

‘<?xml version=”1.0″ encoding=”utf-8″?>
      <L:Clients xmlns:L=”; >
                  <TestGroup xmlns=”TestGroup”>   
                        <Test1>TCLP VOA</Test1>   
                        <Test3>Metals Group1</Test3>  
                  <TestGroup xmlns=”TestGroup”>   

                              ‘TestGroup’ as TG)
SELECT      T.c.value(‘(TG:Test1)[1]’, ‘varchar(20)’) as Test1,
            T.c.value(‘(TG:Test2)[1]’, ‘varchar(20)’) as Test2,
            T.c.value(‘(TG:Test3)[1]’, ‘varchar(20)’) as Test3
FROM      @MyXml.nodes(‘(L:Clients/L:Body/TG:TestGroup)’) T(c)
Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: