Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shaik.zakeer
Posting Yak Master
117 Posts |
Posted - 2010-04-26 : 01:15:33
|
| i have an xml like the belowDECLARE @XML XMLSET @XML = '<Employee> <EmployeeDetails> <EmployeeID>1</EmployeeID> <EmployeeName>aaa</EmployeeName> </EmployeeDetails> <EmployeeDetails> <EmployeeID>2</EmployeeID> <EmployeeName>bbb</EmployeeName> <Employeeadd1>xxx</Employeeadd1> <Employeeadd2>yyy</Employeeadd2> </EmployeeDetails></Employee>'SELECT x.value('local-name(.)', 'VARCHAR(500)') AS FIELDNAME, x.value('.', 'VARCHAR(500)') AS VALUEFROM @XML.nodes('/*/*/*') as n1(x)how can i use the rank functions to get the result like belowFieldName value rankEmployeeID 1 1EmployeeName aaa 1EmployeeID 2 2EmployeeName bbb 2Employeeadd1 xxx 2Employeeadd2 yyy 2do we have any other alternative to get the result like this.Kindly help meThanks Jack |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-04-26 : 04:11:48
|
[code]SELECT y.value('local-name(.)', 'VARCHAR(500)') AS FieldName, y.value('.', 'VARCHAR(500)') AS Value, DENSE_RANK() OVER (ORDER BY n1.x) AS [rank]FROM @XML.nodes('/*/*') as n1(x)CROSS APPLY x.nodes('*') AS n2(y)[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
shaik.zakeer
Posting Yak Master
117 Posts |
Posted - 2010-05-02 : 02:10:32
|
| Thanks friend... awesomeThanks Jack |
 |
|
|
|
|
|