<ProductID>2</ProductID> <ProductName>Chang</ProductName> </Product> </Category> 从上面看出Category元素的Tag为1,Parent为NULL,而Product元素的Tag为2,Parent为1(即Category的Tag值)。这里有一个问题需要解决,那就是在Tag和Parent中存在两套值,这里就需要使用UNION ALL运算符来实现这项功能,UNION ALL运算符的一项功能就是消除查询返回的重复的行。使用UNION ALL时需要注意的是结果集的列数必须相同。 查询语句: SELECT 1 AS Tag,NULL AS Parent, CategoryID AS [Category!1!ID], CategoryName AS [Category!1!Name], NULL AS [Product!2!ProductID!element], NULL AS [Product!2!ProductName!element] FROM Categories WHERE CategoryID < 3 << 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >> |