我有一个表有2列EmployeeId(int)和EmployeeDetails(XMl类型)的表
EmployeeId EmployeeDetails
1
2
我需要输出像
EmployeeId EmpName年龄地址
1 Priyanka 24阿根廷
2 Sarkar 28 Australia
请帮忙,因为我是xml的新手
关于XML的主题,联机丛书有点难以辨认; 您可以尝试使用此站点寻求帮助:http://blogs.msdn.com/mrorke/archive/2005/06/01/423965.aspx 这里有一段代码可以帮助您.
DECLARE @Employees TABLE ( EmployeeID INT , EmployeeDetails XML ) INSERT INTO @Employees ( EmployeeID , EmployeeDetails ) VALUES ( 1 , '' ) INSERT INTO @Employees ( EmployeeID , EmployeeDetails ) VALUES ( 2 , ' Priyanka 24 Argentina' ) 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 ) Sarkar 28 Australia