如何在SSRS中使用STUFF之前进行排序

时间:2017-08-23 22:07:31

标签: sql-server-2008 sorting reporting-services ssrs-2008

我有2个不同的值,我在这里尝试STUFF。这是数量+价格。例如:1- $ 0.36; 100- $ 0.29; 25- $ 0.31。如何在填充前按数量排序? (1,25,100而不是1,100,25)我确实遇到了这个链接Sort data before concatenating using STUFF FOR XML,但它处理了1个值,我正在处理2个值

    SELECT STUFF(
   (SELECT DISTINCT TOP (5) 
        '; ' + (CAST(FLOOR(CASE WHEN PCFBD.Quantity IS NOT NULL THEN PCFBD.Quantity ELSE 1 END) AS VARCHAR)  + '-$' + CAST(REPLACE(REPLACE(RTRIM(REPLACE(
       CASE WHEN PCF.PriceMethod = 0 THEN ROUND(I.CdCost / (100 - PCF.FormulaPercent) * 100, 2) 
            WHEN PCFBH.PriceFormula = 2 AND PCFBD.FormulaPercent IS NULL THEN ROUND(I.CdCost / (100 - PCF.FormulaPercent) * 100, 2)
            WHEN PCFBH.PriceFormula = 2 AND PCFBD.FormulaPercent IS NOT NULL THEN ROUND(I.CdCost / (100 - PCFBD.FormulaPercent) * 100, 2)
            WHEN PCFBH.PriceFormula = 1 THEN ROUND((I.ListPrice * (100 - PCFBD.FormulaPercent)) * .01,2)
            ELSE NULL END, '000' ,'')), ' ','0') + '', '.  ', '') AS VARCHAR))
 FROM              Item AS I 
 INNER JOIN        PriceContractFamily AS PCF ON I.FamilyId = PCF.FamilyId
                 AND I.ItemStatus IN (0, 5) 
 INNER JOIN        StockItem SI ON I.ItemId = SI.ItemId
                 AND SI.WarehouseId = '502E5876-C26B-4E11-8B88-AFE0C34ECF0D'                     
 LEFT OUTER JOIN   PriceContractFamilyBracketHeader AS PCFBH ON PCF.PriceContractFamilyId = PCFBH.PriceContractFamilyId 
 LEFT OUTER JOIN   PriceContractFamilyBracketDetail AS PCFBD ON PCFBH.BracketHeaderId = PCFBD.BracketHeaderId
 WHERE I.ListPrice = @ListPrice
AND LEFT(I.ItemNumber, 6) = @ItemNumber
AND PCF.PriceContractId = @PriceContractId  
 FOR XML PATH('')),1, 2, '') AS QtyPrice                                                        

1 个答案:

答案 0 :(得分:0)

您应该能够在FOR XML PATH语句之前添加ORDER BY。