I have a table having 2 columns EmployeeId (int) and EmployeeDetails(XMl type)
EmployeeId EmployeeDetails
1 <Employee><Employ开发者_如何学JAVAeeDetails><EmployeeName> Priyanka </EmployeeName><Age> 24 </Age><Address> Argentina</Address></EmployeeDetails></Employee>
2 <Employee><EmployeeDetails><EmployeeName> Sarkar </EmployeeName><Age> 28 </Age><Address> Australia</Address></EmployeeDetails></Employee>
I need to have the output like
EmployeeId EmpName Age Address
1 Priyanka 24 Argentina
2 Sarkar 28 Australia
Please help as I am new to xml
Books Online is a bit indecipherable on the subject of XML; you may want to try this site for help: http://blogs.msdn.com/mrorke/archive/2005/06/01/423965.aspx Here's a snippet of code to help you along.
DECLARE @Employees TABLE
(
EmployeeID INT ,
EmployeeDetails XML
)
INSERT INTO @Employees
( EmployeeID ,
EmployeeDetails
)
VALUES ( 1 ,
'<Employee><EmployeeDetails><EmployeeName> Priyanka </EmployeeName><Age> 24 </Age><Address> Argentina</Address></EmployeeDetails></Employee>'
)
INSERT INTO @Employees
( EmployeeID ,
EmployeeDetails
)
VALUES ( 2 ,
'<Employee><EmployeeDetails><EmployeeName> Sarkar </EmployeeName><Age> 28 </Age><Address> Australia</Address></EmployeeDetails></Employee>'
)
SELECT EmployeeID ,
EmployeeName = m.value('EmployeeName[1]', 'varchar(50)') ,
Age = m.value('Age[1]', 'int') ,
Address = m.value('Address[1]', 'varchar(100)')
FROM @Employees e
CROSS APPLY EmployeeDetails.nodes('/Employee/EmployeeDetails') AS e1 ( m )
精彩评论