简体   繁体   中英

Data not displayed in SSRS report, but execting query in SQL shows data

I want to show some data in a report by using a stored procedure:

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 DateKey=@O2QuarterStartDate
        SELECT @DateFrom = MIN([Date]),@DateTo = MAX([Date])  
        FROM DimDate 
        WHERE  O2Quarter=@O2Quarter AND O2Year=@O2Year      
    END

    IF(@O2MonthStartDate IS NOT NULL) 
    BEGIN
        PRINT @O2MonthStartDate
        SELECT @O2Month=O2Month, @O2Quarter = O2Quarter,@O2Year = O2Year  
        FROM DimDate 
        WHERE DateKey=@O2MonthStartDate
        SELECT @DateFrom = MIN([Date]),@DateTo = MAX([Date])  
        FROM DimDate 
        WHERE O2Month=@O2Month AND O2Quarter=@O2Quarter AND O2Year=@O2Year      
    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

When I filter by using the 7 filters above, data is not showing on the report but there are no errors either - why might this be?

Make sure your function is table-based. You don't need to add the date parameters in the WHERE clause because you are already passing those in the function. Test your query by running it first in SSMS.

Here is a simplified version of the query:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM