简体   繁体   中英

Creating time parameter in SSMS 2016 for SSRS report

I'm trying to create a SSRS report that allows users to search work orders by time range in addition to date. For example: requests from 5/1/20-5/27/20 that took place between 5:00 pm and 7:00 pm Below is my stored procedure from SSMS 2016, I commented out the time parameters since they're not working. This produces the unrefined data I need and the date parameters work, it's the time parameters I'm having issues with.

@STARTDATE DATE,
@ENDDATE DATE
--@STARTTIME TIME,
--@ENDTIME TIME
AS

SELECT 
   [PROBLEMCODE]
  ,FORMAT([DATETIMEINIT], 'yyyy-MM-dd') AS 'DATE'
  ,FORMAT([DATETIMEINIT], 'hh:mm tt') AS 'TIME'
  ,[STATUS]
FROM [Cityworks].[azteca].[REQUEST]
WHERE REQCATEGORY IN ('WATER', 'SEWER')
AND [DATETIMEINIT] BETWEEN @STARTDATE AND @ENDDATE
--AND FORMAT([DATETIMEINIT], 'HH:mm') BETWEEN @STARTTIME AND @ENDTIME;

This is my first time posting, so I hope all that made sense! Thank you for your help!

Like I said, assuming that DATETIMEINIT is a datetime / datetime2 / datetimeoffset :

CREATE dbo.YourProc @StartDate date, @EndDate DATE --Or datetime2, etc, depending on requirement
AS
BEGIN

    SELECT [PROBLEMCODE],
           DATETIMEINIT,
           [STATUS]
    FROM [Cityworks].[azteca].[REQUEST]
    WHERE REQCATEGORY IN ('WATER', 'SEWER')
    AND [DATETIMEINIT] >= @STARTDATE
      AND DATETIMEINIT < @ENDDATE;

END;

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