I have the following SQL,
SELECT AT.ID ATT_ID
,VAL.ID VAL_ID
,COALESCE(ATT.Name,AT.Name) AS Name
,COALESCE(VALT.Value,VAL.Value) AS Value
,COALESCE(GT.Name,G.Name) AS GroupName
,AT.KeyAttribute
,AT.[Order]
FROM Attributes AT
LEFT OUTER JOIN AttributesTranslations ATT on (AT.ID = ATT.AttributeID AND ATT.LanguageID = @LanguageID)
LEFT OUTER JOIN AttributesValues VAL ON VAL.AttributeID = AT.ID AND VAL.ProductID = @ProductID
LEFT OUTER JOIN AttributesValuesTranslations VALT on (VAL.ID = VALT.AttributeValueID AND VALT.LanguageID = @LanguageID)
LEFT OUTER JOIN AttributesGroups G ON G.ID = AT.GroupID
LEFT OUTER JOIN AttributesGroupsTranslations GT on (G.ID = GT.AttributeGroupID AND GT.LanguageID = @LanguageID)
WHERE AT.ProductTypeID = (SELECT ProductTypeID FROM Products WHERE ID = @ProductID)
AND ((AT.RetailerID = @RetailerID) OR (@RetailerID = -1))
ORDER BY G.[order],G.Name ,AT.[Order]
FOR XML AUTO, ELEMENTS
It will return,
<AT>
<ATT_ID>2</ATT_ID>
<KeyAttribute>0</KeyAttribute>
<Order>2</Order>
<VAL>
<VAL_ID>32614</VAL_ID>
<Name>Design</Name>
<Value>asfdsa</Value>
<GroupName>zOther</GroupName>
</VAL>
</AT>
<AT>
<ATT_ID>2</ATT_ID>
<KeyAttribute>0</KeyAttribute>
<Order>2</Order>
<VAL>
<VAL_ID>32614</VAL_ID>
<Name>Design</Name>
<Value>asfdsa</Value>
<GroupName>zOther</GroupName>
</VAL>
</AT>
I want the result as,
<AT>
<ATT_ID>2</ATT_ID>
<KeyAttribute>0</KeyAttribute>
<Order>2</Order>
<VAL_ID>32614</VAL_ID>
<Name>Design</Name>
<Value>asfdsa</Value>
<GroupName>zOther</GroupName>
</AT>
<AT>
<ATT_ID>2</ATT_ID>
<KeyAttribute>0</KeyAttribute>
<Order>2</Order>
<VAL_ID>32614</VAL_ID>
<Name>Design</Name>
<Value>asfdsa</Value>
<GroupName>zOther</GroupName>
</AT>