SSRS - Default to show ALL values if parameter is left blank - sql-server

My SSRS report displays a date range (2 parameters) and a multi-selectable value parameter for a field called "MeterNumber".
What I want is for the default value of the multi-selectable parameter to show ALL values until the user specifies one of the values in the list.
I've tried doing this by setting the general tab in the parameter properties to "Allow Multiple Values", and the Available and Default values to equaling the same value fields from the same dataset, but no go.
Any thoughts?

You can use the same dataset that populates the Available Values of the parameter, to populate the Default Values of the parameter.
Then by default, all values are selected when the user first opens the report.

You can assign minimum date and maximum date in your back-end if your date start and date end is empty or null (remember the min date in sql is 1/1/1753 12:00:00 AM and max date is 12/31/9999 11:59:59 PM so your date format should be like that). So when its passed on your parameter it will get all the data within that minimum start date and maximum end date.
This is how you are going to assign min date time in c#
DateTime dateStart = SqlDateTime.MinValue.Value;
and max date
DateTime dateEnd = SqlDateTime.MaxValue.Value;

Do you have any blank and/or null values for MeterNumber in the dataset? This can cause issues with Parameter values. Since in your case you need multiple values, then you can't have null values. Just make sure Allow blank value ("") and Allow multiple values are selected. Then, make sure you don't have NULL values in the MeterNumber column. If you do, then convert to empty string, i.e., ISNULL(AC.MeterNumber, '') as MeterNumber

Just had the exact same problem #Byronyk, however just realised what the issue was (Also aware this post is very old, this is more for those who stumble upon this!)
The issue I found was that I had one extra Value in the available values than in the Default Values, and as such it threw out the default selections.
Once I realised and added it in, the default values were selected again.
I suspect this is the issue, as the date worked fine, the issue was in the 'MeterNumber' parameter

Related

Google Datastudio: Apply Date Range Filter for Two Different Date Columns of Date Source

I have a requirement to have date range filter which can be used for two different date columns of the data source(One at a time either through radio button to choose at which column date range should apply).
Is it possible to achieve this in Google Data studio ?
Workaround:
The general idea is to use let the user set the value of a parameter, which determines the value of a dummy field containing the value of either datetime column. You can then indicate that your table/chart should filter by this datetime field.
Create a parameter in the data source, with the names of the columns you want as possible values. If you want to filter the order_date and completed_date columns, these should be possible options.
Allow the user to set the parameter (e.g. by using a radio button).
Create a calculated field in the data source (e.g. select_date) which, depending on the value of the parameter. For example, create a field user_field:
CASE user_select # this is a parameter
WHEN "order_date" THEN order_date # this is the value of the order_date field
WHEN "completed_date" THEN completed_date # this is the value of the completed_date field
ELSE NULL
END
Set the 'Date Range Dimension' of your chart/table to user_field (the name of the calculated field).
Workaround:
If the table has a primary key, you can make a datablending with itself and in a data set put as a time filter a first field and in the other with the second field.
Example
After that, you should add the metrics and dimensions you need from one of them.
Now when you apply a time filter, it will work on both of them.

Excel Query Parameter Update when Cell Value Changes

I'm using Excel 2013 and I have a sheet that gets data from SQL Server 2012.
The query has 4 parameters and gets their values from cells. The box is checked to Refresh Automatically when cell value changes. I want to avoid using VBA.
Data is returned when correct values are in the cells referenced by the parameters.
The issue is with the cells that are dates. In another cell I create a formula that checks if the date is valid, if it is valid then format the entered value as YYYY-MM-DD else format today's date. On the first change the data is updated, but on subsequent changes the data doesn't update. The cell with the formula is used as the value for the parameter.
The issue seems to be that cells used for query parameters can only contains data or a simple function, no nested functions, for a change event to be recognized.
In my case: Cell I4 formats the user entered start date using =TEXT(F4,"yyyy-mm-dd"). If it is a date it is converted to text as SQL expects it else it is the same as the input. Cell J4 contains function for first day of current month =TEXT(TODAY()-DAY(TODAY())+1, "yyyy-mm-dd"). The cell used for the parameter is H4 and it contains =IF(F4=I4, J4, I4).
The next row (5) is similar testing the end date and J5 provides the month end date: =TEXT(EOMONTH(TODAY(),0), "yyyy-mm-dd") . Then the parameter cell for the end date contains =IF(F5=I5,J5, I5).
My next step is to take the query to a stored procedure for better input validation. Since excel seems to only allow 1 parameter for stored procedures (unless ODBC is used) I will have to concatenate the inputs is a cell like this: =TRIM(CONCATENATE(H2, "■",F3, "■", H4, "■", H5)) . Then split the criteria in the SP. Hope this helps someone.

SSRS Date Parameter Mismatching

I have an issue with SSRS where when posting in a DD/MM/YY value via URL string into a Parameter it decides to read the Day value as the Year, the Month as month, but the Year goes into Day value, for example:
I am inputting the date of 30/08/17 via an ERP System which then generates a string to be used as an URL to generate the report, this date value should then go into a parameter called fiAsOfDate which is Date/Time data type, but at this point it is reading the value as 08/17/1930 inside the Parameter list, even though the URL remains at 30/08/17.
This happens prior to the Query being processed, and the fiAsOfDate parameter then gets formatted through to to MMDDYYYY to be processed within the Query, but the issue is specifically when the parameter is having the value loaded from the URL into the parameter value, and I was hoping if anyone could assist me on this please?
I should also add, this original date is coming from an ERP system which will have regional based date formatting, as it is used internationally, so I cannot restrict myself to one input format, and it should be using regional settings, matching that of the Reporting server that it is based on.
Kind Regards,
James W. Acklam.
To avoid regional setting issues you can change the date into a known integer or string format: I use CONVERT(NVARCHAR, YourDate, 112) to get a string '20170830'. The regional settings won't recognize that as a date and so won't auto-parse it into MM/DD/YYYY or DD/MM/YYYY. Of course, you'll need to parse that yourself so you can use it in the report, but at least you know the format.
This issue was down to my own misunderstanding that the DataSource I was pulling data from worked only in DMY format. Converting dates from parameters format to DMY format and processing that through the DataSet's query resolved the issue.

Timestamp format modification in Oracle 10g [duplicate]

I have a function which should accept date in a format DD-MON-YY and should display in the format DD-MM-YYYY. The function I have created is :
create or replace function PRINT_IT(abc date)
RETURN DATE
IS
v_date DATE;
BEGIN
if regexp_like(abc,'^[0-9]{2}-[a-z]{3}-[0-9]{2}$')
then
v_date := TO_DATE(abc,'DD-MM-YYYY');
else
dbms_output.put_line('wrong format');
end if;
dbms_output.put_line('The date is ');
return v_date;
END PRINT_IT;
but the value returned is always wrong date format!!
No, it's not. Your date is being output in the format specified by your NLS_DATE_FORMAT. I you want to display if differently then change this parameter for your session:
alter session set nls_date_format = 'dd-mm-yyyy'
Note the word display. That's all this does. That's all you should consider doing. The way a date is displayed in no way effects the way it is stored.
More normally you might use TO_CHAR() with an appropriate format model to display a date, i.e. to_char(my_date, 'dd-mm-yyyy'). It will no longer be a date but a character.
It doesn't look like you want to display a date as you've said. You're returning the value from your function, in which case I would stick with what you have. You only need to transform a date into an appropriate format for display when taking it out of the database, always store it as a date in the database. This in turn means that it doesn't matter what it looks like when stored in the database, merely that it is actually a date.

date comparison in oracle for the year ends with 00

The date stored in my database is 01-01-1900 for field emp_doj(Data Type DATE).
But while retrieving the data, the value is 01-jan-00, even though formatted with dd-mm-yyyy.
I am comparing retrieved date field with some other date in SQL query.
select *
form persons
where per_join = to_date(to_char(i.emp_doj,'DD-MM-YYYY'),'DD-MM-YYYY')
Here the value of to_date(to_char(i.emp_doj,'DD-MM-YYYY'),'DD-MM-YYYY') results in 01-01-00, instead of 01-01-1900
I suspect it's your default NLS settings for the IDE you are using that is merely displaying the dates with a two digit year. Oracle does not store dates in any specific format. It stores them in a binary format internally.
Therefore I suggest you check the settings for your IDE and/or database and you will see the NLS date format set to DD-MM-YY, alter this and set it to DD-MM-YYYY and you will see the dates as you wish to see them.
As for your query, why use TO_CHAR and then TO_DATE? If emp_doj is a date field and per_join is also a date then just compare them directly for equality. If you are trying to cut the time portion off your emp_doj values then just use TRUNC().
For examples and reference on NLS: http://www.orafaq.com/wiki/NLS
More here: http://www.oracle.com/technetwork/database/globalization/nls-lang-099431.html
select to_char(emp_doj,'dd-mm-yyyy') from yourtable
I have got some temporary solutions it currently works for me, I simply changed my select query to
select *
form persons
where to_date(per_join,'DD-MM-YYYY')= to_date(i.emp_doj,'DD-MM-YYYY')

Resources