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 ANSI_NULLS ON
DECLARE @MyXML Xml
SET @MyXml =  

     
             
                     
                        TCLP VOA   
                        TCLP-SVOA   
                        Metals Group1  
                 
                     
                        Cynide   
                        Mercury   
                        TO-15  
                   
           
      ‘

;WITH XMLNAMESPACES (‘http://sqlhub.com/client/’ as L,
                              ‘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
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of
http://www.SQLHub.com
Microsoft SQL Server Blog. Fight the fear of SQL with SQLHub.com. Founder is Ritesh Shah

One thought on “Read typed XML in SQL Server 2008

  1. Pingback: WHERE clause on XML column in SQL Server table

Comments are closed.