问题
I want to use one parameter for date and another one for time in my reports as shown below.
Start Time [16/01/2012][12.00 am]
Can anyone help me regarding that?
回答1:
Sure it is a multiple step process:
- Set up a variable of TEXT as 'DATE' as the variable value and prompt
- Set it's 'Default Values' in the left pane to be '1/16/2012'
- Set up a variable of TEXT as 'TIME' as the variable value and prompt
- Set it's 'Default Values' in the left pane to be '00:00'
Set up a dataset, 'AvailableDateTime' to combine the two into a legitimate datetime field:
SELECT CAST(@Date + ' ' + @Time AS DateTime) AS Datetime
Set up a third variable of DATETIME to be 'DATETIME' as the variable value and prompt.
- Set up this variable to use 'AVAILABLE VALUES' on the left pane of properties to be 'Get values from a query'. Use the dataset from step 5.
You now have set up a separate field for data and time.
Further consideration to avoid user input error. You may wish to tie the first variables to be selectable ONLY FROM values you set in available values or from a query. The problem being if a user fat fingers the date or time it will not run as the system is only trying to combine two strings and make a datetime out of it. You may wish to list values directly from a query from the getgo.
EDIT FOR CHANGING FIRST TWO VARIABLES:
- You may set the first variable as datetime which gives the end user a calendar.
You can set a second dataset up to get available times for an end user:
declare @time table ( tm int) declare @cursor int = 0 while @cursor <= 23 Begin insert into @time values (@cursor) set @cursor += 1 End select cast(CAST(tm as varchar) + ':00' as time) as HourOfTheDay from @time
Setting your second variable to get values from a query that is made in step 2 directly above.
You should now be able to put the values together as above.
回答2:
As I said in my comment, SSRS
does not allow you to have separate parameters for Date
and Time
.
It has only one parameter Date/Time
.
As I see you have two options.
- Add a text parameter and consider that as time. You could then do some validation depending on what tech you are using.
- Another way to solve this would be creating a list of possible
values. You select
Integer
type, for instance and then create a list ofAvailable Values
. (see images)


来源:https://stackoverflow.com/questions/14437475/separate-parameters-for-date-and-time