简体   繁体   中英

I'm trying to filter a SQL dataset by today's date in SSRS using Report Builder

I have an SSRS report that calls a stored procedure. Here's the procedure:

USE [TSC-Telaid]
GO
/****** Object:  StoredProcedure [dbo].[TW_spRPTAllReceiverInventory]    Script Date: 10/4/2017 2:06:58 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



ALTER PROCEDURE [dbo].[TW_spRPTAllReceiverInventory] 
@SiteId varchar(50), 
@ReceiverId int
AS

BEGIN

DECLARE @SQL varchar(8000), @Index int, @Value varchar(500), @Source varchar(100)

SELECT @Index = CHARINDEX('Initial Catalog=', ConnectionString) + 16, @Value = ConnectionString
FROM CustomerSetting
WHERE SiteId = @SiteId

SET @Source = '[' + SUBSTRING(@Value , @Index, CHARINDEX(';', @Value, @Index) - @Index) + ']'

SET @SQL = 'SELECT R.SiteId, L.*
        FROM ' + @Source + '.[dbo].[vwReceiver] R JOIN  ' + 
            @Source + '.[dbo].[vwInventory] L ON R.ReceiverId = L.ReceiverId
        WHERE R.ReceiverId = ' + CAST(@ReceiverId as varchar)

EXEC(@SQL)

END

I pass in @SiteId & @ReceiverID on the dataset. One of the fields I get back is DateReceived. I want to filter the dataset so that it only returns DateReceived = today() but it's not working.

I've also tried setting the filter expression to DateReceived BETWEEN DateAdd("d",-1,Today()) & DateAdd("d",1,Today())

I'm not new to SQL but fairly new to SSRS.

I think I figured it out. I had to adjust the expression to:

DateReceived is between =DateAdd(DateInterval.Day, 0, Today()) AND =DateAdd(DateInterval.Day, 1, Today())

This seems to be working.

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