2016-12-21 38 views
0

我想通過使用存儲過程,以顯示在報告中的一些數據:數據在SSRS報告中沒有顯示,但在SQL execting查詢顯示數據

ALTER PROCEDURE [dbo].[usp_GetThirtyDaysSims] 
(
    @DateFrom DATETIME = NULL, 
    @DateTo DATETIME = NULL, 
    @O2QuarterStartDate INT = NULL, 
    @AreaId INT = NULL, 
    @StoreId INT = NULL, 
    @O2MonthStartDate INT = NULL, 
    @TransactionType NVARCHAR(1000) 
) 
AS 
BEGIN 

    DECLARE @O2Quarter AS INT 
    DECLARE @O2Year AS INT 
    DECLARE @O2Month AS INT 

    IF (@AreaId = 0 OR @AreaId = 999999999) 
    BEGIN 
     SET @AreaId = NULL 
    END 

    IF (@StoreId = 0 OR @StoreId = 999999999) 
    BEGIN 
     SET @StoreId = NULL 
    END 

    IF (@O2QuarterStartDate = 0 OR @O2QuarterStartDate = 999999999) 
    BEGIN 
     SET @O2QuarterStartDate = NULL 
    END 

    IF (@O2MonthStartDate = 0 OR @O2MonthStartDate = 999999999) 
    BEGIN 
     SET @O2MonthStartDate = NULL 
    END 

    IF(@O2QuarterStartDate IS NOT NULL) 
    BEGIN  
     SELECT @O2Quarter = O2Quarter,@O2Year = O2Year 
     FROM DimDate 
     WHERE [email protected] 
     SELECT @DateFrom = MIN([Date]),@DateTo = MAX([Date]) 
     FROM DimDate 
     WHERE [email protected] AND [email protected]  
    END 

    IF(@O2MonthStartDate IS NOT NULL) 
    BEGIN 
     PRINT @O2MonthStartDate 
     SELECT @O2Month=O2Month, @O2Quarter = O2Quarter,@O2Year = O2Year 
     FROM DimDate 
     WHERE [email protected] 
     SELECT @DateFrom = MIN([Date]),@DateTo = MAX([Date]) 
     FROM DimDate 
     WHERE [email protected] AND [email protected] AND [email protected]  
    END 

    SELECT Area,StoreName,SUM(Tariff) SumOfTariff, COUNT(1) NoOfSimsSold 
    FROM [dbo].[ufn_GetThirtyDaysSimsData](@DateFrom,@DateTo) FT 
      INNER JOIN DimDate DD ON FT.TransactionDateId = DD.DateKey 
    WHERE (@DateFrom IS NOT NULL AND DD.[Date] >= @DateFrom) 
      AND (@DateTo IS NOT NULL AND DD.[Date] <= @DateTo) 
      AND (FT.AreaId = @AreaId OR @AreaId IS NULL) 
      AND (FT.StoreId = @StoreId OR @StoreId IS NULL) 
      AND (FT.TransactionType = @TransactionType OR @TransactionType IS NULL) 
    GROUP BY Area,StoreName 
    ORDER BY Area,StoreName 

END 

當我通過使用上述7個過濾器過濾,數據沒有在報告中顯示,但也沒有錯誤 - 爲什麼會這樣?

回答

0

確保你的函數是基於表的。您不需要在WHERE子句中添加日期參數,因爲您已經在函數中傳遞了這些參數。首先在SSMS中運行它,以測試您的查詢。

下面是該查詢的簡化版本:

SELECT Area, StoreName, SUM(Tariff) SumOfTariff, COUNT(1) NoOfSimsSold 
FROM [dbo].[ufn_GetThirtyDaysSimsData](@DateFrom,@DateTo) FT 
     INNER JOIN DimDate DD ON FT.TransactionDateId = DD.DateKey 
WHERE FT.AreaId = @AreaId 
     AND FT.StoreId = @StoreId 
     AND FT.TransactionType = @TransactionType 
GROUP BY Area, StoreName 
ORDER BY Area, StoreName