2011-08-06 125 views
0

我對tsql和ssrs很新,我只有3天的培訓,所以要溫柔! 我想寫一份報告,顯示訂單遲到的每個月的次數,並顯示我們準時到達的百分比。到目前爲止,我得到這個:tsql ssrs過期訂單的百分比

SELECT 
    COUNT(*) AS NoOfWo, 
    CASE WHEN DATEDIFF(d, CompletionDate, LastActualCompDate) <= 0 THEN 'OnTime' ELSE 'Late' END AS Performance, 
    DATENAME(mm, LastActualCompDate) AS month 
FROM   WipHeader 
WHERE  (LastActualCompDate >= CAST(DATEPART(year, GETDATE()) AS varchar) + '-01-01') 
GROUP BY 
    CASE WHEN DATEDIFF(d, CompletionDate, LastActualCompDate) <= 0 THEN 'OnTime' ELSE 'Late' END, MONTH(LastActualCompDate), DATENAME(mm, LastActualCompDate) 
ORDER BY 
    MONTH(LastActualCompDate) 

這晚,在時間和訂單總數每月數今年迄今返回數字,但我不能工作,如何回報百分比是多少? 任何幫助將不勝感激! 謝謝。

回答

0

由於gbn,但都沒有工作。也許這是我成爲一個新手,並不知道如何粘貼它。SQL選項的確如此,但數據不好,它返回的百分比超過了100%,這是不可能的。 我修正了這個問題。查詢現在看起來像:

SELECT  COUNT(*) AS NoOfWo, DATENAME(mm, LastActualCompDate) AS month, LastActualCompDate, CompletionDate, JobNo 
FROM   WipHeader 
WHERE  (LastActualCompDate >= CAST(DATEPART(year, GETDATE()) AS varchar) + '-01-01') AND (NOT (LastActualCompDate IS NULL)) 
GROUP BY MONTH(LastActualCompDate), DATENAME(mm, LastActualCompDate), LastActualCompDate, CompletionDate, JobNo 
HAVING  (NOT (LastActualCompDate IS NULL)) AND (NOT (LastActualCompDate IS NULL)) AND (NOT (MONTH(LastActualCompDate) IS NULL)) 
ORDER BY MONTH(LastActualCompDate) 

然後在SSRS我添加了一個新的計算字段到名爲CalcDateDiff這種表達數據集:

=datediff("d",Fields!CompletionDate.Value,Fields!LastActualCompDate.Value) 

然後在表我添加了名爲「延遲」的新列,「準時」和「%準時」和下面分別添加了表情:

=count(iif (fields!CalcDateDiff.Value>0,1,nothing)) 
=count(iif (fields!CalcDateDiff.Value<=0,1,nothing)) 
=count(iif (fields!CalcDateDiff.Value<=0,1,nothing))/Sum(Fields!NoOfWo.Value) 

然後設置最後一個百分比的文本框屬性,並通過本月新增一組。

嘿presto。它只花了我4天!

3

最簡單的方法是,如果你想讓它有超過在SSRS

添加此COUNT給總晚+準時的,然後做了個
SELECT 
    COUNT(*) OVER() AS Total, 
    COUNT(*) AS NoOfWo, 
    CASE WHEN DATEDIFF ... blah 

或者,在SQL(可能需要一些嵌套,不測試)

SELECT 
    COUNT(*) OVER() AS Total, 
    COUNT(*) AS NoOfWo, 
    CAST(100 AS float) * COUNT(*)/COUNT(*) OVER() AS percentage 
    CASE WHEN DATEDIFF ... blah