How to put XML data into an XML dataype column
By Allen Stoner
The easiest way to put XML data into an XML datatype column in Microsoft SQL server is to use the INSERT INTO command and just put the XML in as a string.
Insert Into tblCustomerDeals (LastName, FirstName, MiddleName, Data)
values
('Doe', 'John', '', '<FormData><Data
Name="FirstName">John</Data><Data Name="LastName">John</Data></FormData>"')
Related FAQs
Microsoft SQL Server 2008 has an XML data for storing such data. A nice thing about using this datatype instead of just a large text column is the ability to query the XML column and retrieve elements and their values. Using this technique you can create a view that makes the XML data look a lot like a regular MS SQL table.
The bold line is the statement to pull the first element with a value of FirstName from within the XML in the xml datatype column.
How to put XML data into an XML dataype column (1200 Views)