Create a XML select from a table definition.

Rédigé par M Sozezzo - - Aucun commentaire

Transform table definition to XML select, it can be useful when we need to create many XML select or re-create it.

Result:


SELECT

  [Message].value('(msg_Customers/Customers/CustomerID)[1]', 'nchar(5)') as [CustomerID]

, [Message].value('(msg_Customers/Customers/CompanyName)[1]', 'nvarchar(40)') as [CompanyName]

, [Message].value('(msg_Customers/Customers/ContactName)[1]', 'nvarchar(30)') as [ContactName]

, [Message].value('(msg_Customers/Customers/ContactTitle)[1]', 'nvarchar(30)') as [ContactTitle]

, [Message].value('(msg_Customers/Customers/Address)[1]', 'nvarchar(60)') as [Address]

, [Message].value('(msg_Customers/Customers/City)[1]', 'nvarchar(15)') as [City]

, [Message].value('(msg_Customers/Customers/Region)[1]', 'nvarchar(15)') as [Region]

, [Message].value('(msg_Customers/Customers/PostalCode)[1]', 'nvarchar(10)') as [PostalCode]

, [Message].value('(msg_Customers/Customers/Country)[1]', 'nvarchar(15)') as [Country]

, [Message].value('(msg_Customers/Customers/Phone)[1]', 'nvarchar(24)') as [Phone]

, [Message].value('(msg_Customers/Customers/Fax)[1]', 'nvarchar(24)') as [Fax]

FROM   [Customers]

WHERE  [Message].exist('/msg_Customers/Customers') = 1

 

Lire la suite de Create a XML select from a table definition.

Fil RSS des articles de ce mot clé