Rana_kgec
Rana_kgec

Reputation: 46

Separate parameters for Date and Time

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?

Upvotes: 1

Views: 5393

Answers (2)

djangojazz
djangojazz

Reputation: 13170

Sure it is a multiple step process:

  1. Set up a variable of TEXT as 'DATE' as the variable value and prompt
  2. Set it's 'Default Values' in the left pane to be '1/16/2012'
  3. Set up a variable of TEXT as 'TIME' as the variable value and prompt
  4. Set it's 'Default Values' in the left pane to be '00:00'
  5. Set up a dataset, 'AvailableDateTime' to combine the two into a legitimate datetime field:

    SELECT        CAST(@Date + ' ' + @Time AS DateTime) AS Datetime
    
  6. Set up a third variable of DATETIME to be 'DATETIME' as the variable value and prompt.

  7. 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:

  1. You may set the first variable as datetime which gives the end user a calendar.
  2. 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
    
  3. 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.

Upvotes: 1

eestein
eestein

Reputation: 5114

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.

  1. Add a text parameter and consider that as time. You could then do some validation depending on what tech you are using.
  2. Another way to solve this would be creating a list of possible values. You select Integer type, for instance and then create a list of Available Values. (see images)

enter image description here

enter image description here

Upvotes: 1

Related Questions