查询树视图控件,有时包含由于控件的数据绑定而引发异常的空元素(当元素中没有属性时)文本值设置为“GrandChildOfFirstRow”
我确实通过 xquery 在我的查询中摆脱了它们,但是有没有另一种方法可以做到这一点,或者有一种更好的更聪明的方法来摆脱那些空元素,(我需要左外连接来获得这个查询的正确记录)或者是可以将 xquery 代码组合成更短的代码:
询问:
declare @x as xml
set @x =
(
SELECT distinct
Table1.AssetObjID, Table1.Asset_ID , Table1.FromLR, Table1.AssetType + ', ' + Table1.StreetName + ', ' + Table1.FromMunicNo as FirstRow,
Table2.ACIObjID ,Table2.PAssetObjID, Table2.Feature_ID + ', ' + Table2.FeatureName AS ChildOfFirstRow,
Table3.ITMObjID ,Table3.Item_ID + ',' + Table3.[DESC] as GrandChildOfFirstRow
FROM Table1 left outer join
Table2 ON Table1.AssetObjID = Table2.PAssetObjID left outer join
Table3 ON Table1.AssetObjID = Table3.AssetObjID AND Table2.ACIObjID = Table3.ACIObjID
where Table1.AssetType ='xxxx'
for xml auto,root('xml')
)
--what it does is it only grabs one empty element and deletes only occurrences of that
--specific element for the whole file
--so If I have 2 or more elements which are empty in an xml file
--I will have to repeat that code each time
SET @x.modify('delete //*[not(node()) and not(./@*)]')
SET @x.modify('delete //*[not(node()) and not(./@*)]')