Excel Query Parameter Update when Cell Value Changes - sql-server

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.

Related

SSRS report - export to excel date time filteration

Populating an SSRS report from dyanmic dataset i.e. number column and order of columns may vary based on condition, and this report on trying to export to excel. But in exporting date column filtration not working. Finds the reason is I bind the column in string format.
Sample data format to understand. Here the columns & order of columns may vary as per condition.
And I am converting this to below format and passing to SSRS as dataset.
And populating report by grouping with ROW_NO & COL
Then I tried to convert DOB column to date time.
For converting DOB to date format changed return type of DOB from sql query as datetime, converted column value to date time using CDate() in SSRS and formatted in own format (dd-mmm-yyyy).
Below expression used for converting to date time:
IIF((Fields!COL.Value="DOB") ,CDate(Fields!VALUE.Value),(Fields!VALUE.Value))
But showing #Error for columns data type other than date time:
Go to your detail textbox in the DOB column. And use the following expression:
=Format(CDate(Fields!DOBValue.Value), "dd-MM-yyyy")
This way the date in your DOB column will show 23-01-2018
Note: The expression just works if in the Fields!DOBValue.Value field are just dates. If there is a N/A it will throw an error. Then you have to clear the N/A first.
And if you want to export it to Excel you need to set the language in your report properties (use your region) and go to your textbox where you wrote in the above expression under Textbox properties > Number chose Date format.
UPDATE
Based on your updated question I think I found the error. The problem is your writing of the month names combined with the report language. My report language is set to DE. For me the following works:
=CDate("15-Mai-94") 'Result 05.05.1994
But this dosent work:
=CDate("15-May-94") 'Result =Error
The second one works, when I set the report language to EN but then the first one throws an error

SSRS Subreport Inside a Table Cell not Retrieving Parameters Properly?

I have an SSRS Report using a Table.
You can select multiple Clients and Periods and for every pair there will be a row in the table. So 2 Clients * 3 Periods = 6 rows.
Now... there are some cells that are more complicated than having a single value and I want to place a subreport inside these cells. The Subreport will take the Client and Period for that particular Row as params.
This is where the issue comes in. The Parameters will not pass properly.
I can put Parameters!ClientID.Value(0) as an expression for example and it will pass the first ClientID properly but if I just put Parameters!ClientID.Value it breaks... And I want the Client/Period for the current row.
But how is it that I can't pass the params but CAN fill a new dataset for every row based on that Client/Period pair??
Note that I'd really prefer not to have to edit the SP that builds that dataset to return the Client/Period itself. Sure that would work.. but WHY would that be needed when I have the Parameters?
Any ideas? I'm doing this in a Visual Studio Report Project.
If I've understood correctly you don't need to use the parameter. You need to use the value of the field from the dataset. So if your table shows client and period then the parameter values passed in would be =Fields!Client.Value and =Fields!Period.Value
Client Period SubReportCell
Bob 2017 "subreport here passing in Bob, 2017"
Geoff 2015 "sub report here passing in Geoff, 2015"
You should just be able to choose these from the dropdown lists in the subreport setting dialogue box.

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

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

SQL Server Report Builder : Concatenate data type "date" and "time"

I am working with SQL Server Report Builder 2008 R2.
I have a dataset that contains DateEntry (date, null) and TimeStampAuto (time(7), null) columns. I am trying to write an expression for concatenating those two values, so I can put it under DATETIME column on the report table. I tried the following but it does not work. It displays "#Error."
=First(Fields!DateEntry.Value, "Report1) & " " & First(Fields!TimeStampAuto.Value, "Report1)
When I just put the first part of the expression shown above, the report displays the date with some random time value (5/1/2015 12:00:00 AM). However, I did not put any time value in DateEntry. I only put the dates.
When I put the second part of the expression shown above, the report displays correct time that the data has.
I don't know why I can not concatenate those two.
The system type of the DateEntry.Value will be a DateTime value which is the readon that your report is showing 5/1/2015 12:00 AM even though it is only a date field in the database.
You need to format the date to only include the day,month and year to remove the included default time of 12:00 am
you will probably need to check for null values in both your date and time fields. you will also need to format the time filed to exclude any default date information.

Grab Value from Cell as a Format

I am using VBA to pull in a bunch of data from several workbooks into several worksheets and then process that data later.
WorkFlow: As I pull the data into my workbook, I first place all my data into arrays before outputting them into my worksheets.
Problem
While I am pulling in data, I noticed that some of the "Hours" or "Work Order Number" data are pulled into my arrays in the form of dates or datetime, when they should just be some number format.
e.g.:
I should be getting:
Number of Hours: 2; Work Order Number: 41235612
Instead, I am getting:
Number of Hours: 0-Jan-00 (equivalent to 1/0/1900, which was originally entered as "0")
Work Order Number: 0-Jan-00
I found that the issue lies in the source documents, where it looks like Excel may have automatically (although incorrectly) converted those cell values into a date type form, when first entered as a plain number.
Question
How can I pull data from the different documents into my arrays so
that all values in that column come out as what they should be (a
Number)?
Is there a way to format the value before placing it into the array?
Can I format the value into a number format like the "General" number format (or something that makes sense) while it is being pulled?
I would rather not make any changes within the source documents, and just format the values I am pulling as I pull them.
you can use Range().value2 instead of .value property
the .value2 dont accept Currency and Date formats, so it should read your hours values properly.
for example cell A1 has value 2 and saved with Date format.
so Range("A1").value will return date value "1/2/1900"
Range("A1").value2 will return numeric value 2 you can save in your array.
You can format the values with Clng() or CDbl().
for example:
CDbl(Range("A1").Value)
But if the cell has non numeric value, for example text, code throws an error!
And you can format the cells (source or destination) with .NumberFormat property
Range("A1").NumberFormat = "General"

Resources