SQL Report Builder Error: Argument not specified for parameter 'DateValue' of 'Public Function Day(DateValue As Date) As Integer' - sql

I'm quite new to Report Builder, and looking to apply the solution from this question to a report I'm working on. I have #startDate established as a Parameter, but trying to set its value to = dateadd(day, 1 - datepart(dayofyear, getdate()), cast(getdate() as date)); gives me this error.
The Value expression for the report parameter ‘startDate’ contains an error: [BC30455] Argument not specified for parameter 'DateValue' of 'Public Function Day(DateValue As Date) As Integer'.
Now, I can set the Default Value of #startDate to =Today() and it works fine...except for the fact I can't change the date from that in the report itself, without establishing some Available Values. However, whether the above expression is set to Available or Default Values, the report crashes with that error message.
I would like to keep =Today() as the Default Value, with the above expression as one of the Available Values. Can anyone explain to me what I may be doing wrong, and the most sensible solution to it?

Try set this as your default value within Report Builder itself, Parameter properties - Default Value - fx:
=DateValue(CStr(Year(Today())) + "-01-01")

Related

Conversion failed when converting date and/or time from character string when attributes and parameters are the same data type

I'm running a very simple query where I'm declaring an attribute (#BeginDate) and setting it to equal a report parameter (BeginDate). Both the attribute and the parameter have datetime data types
Report Parameters Setup
DECLARE
#BeginDate datetime
SET #BeginDate='BeginDate'
SELECT *
FROM MessageDeliveries AS MD
WHERE MD.ProcessStart >='BeginDate';
When I run the report I receive the following error message: Conversion failed when converting date and/or time from character string.
Any thoughts on how to correct this?
It's an SQL database. I figured out the solution to my issue. The:
SET #BeginDate='BeginDate'
clause was missing the ^. It should be:
SET #BeginDate='^BeginDate^'
When I made that change the query worked.

PSQL: Syntax error when passing set date variable into datetime

I'm working server-side (using SSH) in psql, where I set variables using the '\set' command.
My concern is this: I have a query where I'm inserting a set string (date) into a datetime, but I get thrown a syntax error.
Simple example:
SELECT
network_no,
program_no,
national_datetime.
FROM
views
WHERE
national_datetime
between ':from_date 06:00:00'
and ':to_date 05:59:59'::timestamp + '1 day'::interval
Where 'from_date' and 'to_date' have been set accordingly:
\set from_date 2017-07-10
\set to_date 2017-07-16
I know normally with dates you're supposed to set three sets of apostrophes to read it in correctly (I never looked up the reason), but I'm feeding this date into a datetime, so I figured using no apostrophes would work, but I get thrown this error:
ERROR: invalid input syntax for type timestamp: ":from_date 06:00:00"
LINE 40: between ':from_date 06:00:00'
Normally in a bash script this would work since it just passes the literal string value, but in this case, whether I put no or one set of apostrophes around the date values it won't pass the value (I'm assuming because of the way PSQL handles set variables.
I know there's ways around this, but I'm looking for a reason why something like this would be happening, and whether there's a simple way to fix the "invalid input syntax"--whether it be through casting a variable, setting the variable differently, etc.
Many thanks in advance!
:from_date is a variable that is not a string.
Here is a way to do it:
date :from_date + time ' 06:00:00'
see doc at https://www.postgresql.org/docs/9.2/static/functions-datetime.html

Argument type mismatch error using the DaysBetween() function in a calculated measure

I am using icCube 5.0.1 and in the process of upgrading to 5.1.
I am attempting to use the Builder to create a Calculated Measure using the following formula: DaysBetween([LastReportingDate], Today())
[Measure].[LastReportingDate] is a measure within the cube with a Date data type.
The purpose is to create a calculated measure that provides the number of days between [Measure].[LastReportingDate] and today and use it within a report.
When I add the new calculated measure to a report table, the column cells are filled with 'error', and when I hover over a cell the error message reads: DaysBetween(): argument (0) type mismatch: expected 'date' got: 'measure'.
Manual reference: http://www.iccube.com/support/documentation/mdx/DaysBetween.php
Any hints? Many thanks!
Can you use the memberValue property:
DaysBetween([LastReportingDate].MemberValue, Today())
(p.s. I use Pyramid not icCube so this may be way of the mark!)
Assuming the [LastReportingDate] is a time dimension (i.e., with the member key being an actual date (and not a string representing a date) ) you can do the following:
DaysBetween( [LastReportingDate].KEY, Today() )
In case [LastReportingDate] is a [Measures] of type Date, you can use the Value() function to get its actual date as following:
DaysBetween( [Measures].[LastReportingDate].Value, Today() )
Note: If the key is a string, please edit your question with its pattern description.
After more research and experimentation, I solved the problem as follows:
I used the following formula for the calculated variable: Today()-[LastReportingDate]
I used the following Cell Properties entry: Format_String = '#,##0' Note that without using the the Format_String, the report displayed a date.
Thanks to all for your assistance.

Why does SSRS Independent parameter is cascading by default

I have a report which currently has four parameters
1) BatchID
2) ProductName (dropdown parameter populated based on the batch ID)
3) StartDateTime (Date/time parameter with default value set to =Now)
4) EndDateTime (Date/time parameter with default value set to =Now)
When I run the report the StartDateTime and EndDateTime are greyed out why? As they are independent parameters I would have thought it will be enabled by default.
The next question I have is the delay, after entering the first parameter the second parameter is populated as expected. However after selecting the second parameter from the dropdown. There is a delay of over 30 seconds to populate the StartDateTime and EndDateTime parameter(s) with the current datetime.
I don't know if I did a good job in explaining my question. Any help.
Note that the problem of having a disabled date type of parameter for SSRS only occurs when the date/time parameter’s default value is an expression like =Now. If the default value is not set or is set to a literal value like 1/1/2018, the control functions as expected — it is enabled.
"Parameter order is important when you want to show users the default value for one parameter before they choose values for other parameters"
Ref:http://msdn.microsoft.com/en-us/library/cc281392.aspx
The controls after non-default parameters are disabled the user picks something, so order is important. The date/time control won’t be enabled until it evaluates its default value expression. It is stated that the delay you mentioned here is intended to allow this parameter’s expression to use the proceeding parameter’s value in its computation.
Ref2: https://bengribaudo.com/blog/2011/03/02/595/ssrs-datetime-parameter-disabled-when-default-value-expression-is-used

If - Strange Behavior in Detecting Type

I discovered this strange behavior in VB.Net today in trying to work with nullable DateTime data. I am pulling a DateTime value out of an XML file for inserting into a database, and I want to allow for an empty value. So I thought I should use If to prevent casting errors:
Dim LastRun As DateTime? = _
If(rowData("LastRun") = "", Nothing, CType(rowData("LastRun"), DateTime))
It seems like this should return a value of Nothing in the case that the If is false, or a value of the date time from LastRun if the value is not blank. Instead, when the If condition returns false, I get a value of DateTime.MinValue, which causes an exception on insert to the database due to SQL DateTime underflow.
I was able to fix it by using DateTime? as the cast in the last parameter, but this behavior seems odd to me. The expected type is clearly DateTime? because that's the variable type. Also, the narrowest type that can allow for both possible result values is DateTime?, since it could be either a DateTime or Nothing. And yet somehow it decides that the result value should be DateTime and then I guess typecasts Nothing to DateTime.MinValue? What is going on here?
Part of the problem is I'm used to C#, and the equivalent expression rowData["LastRun"] == "" ? null : (DateTime)rowData["LastRun"]) doesn't even compile (as expected), because there's "no implicit conversion between DateTime and null."
Nothing is not the same as null in C#, it is a mixture between null and default(T). So when you use Nothing on a value type(like the structure DateTime) you get it's default value what is DateTime.MinValue.