I tried all kinds of variations of the following in my ssrs expression:
=iif(Fields!varchar.Value = "ABC20", Fields!StartDate.Value,Nothing)
It either yields the False clause, the first date field, or it shows as #Error when debugging.
The data type of StartDate is Date (Format= yyyy-mm-dd). Your help in resolving this is much appreciated.
Related
I'm creating a ms-access query to filter by month. I have my list of dates, filter by month using Month(8) as criteria in the field, and am getting a data type mismatch error. I'm not putting the number in quotation marks and I know the field I'm adding criteria to is in MM/DD/YYYY format because I'm pulling it from a query where I changed it to that format. I'm sure it's a simple fix but I am VERY new to ms-access. Thank you in advance for your help.
I'm pulling it from a query where I changed it to that format.
That is your trouble. Pull the date field as is, not as a formatted string.
Then this SQL will work:
Select * From YourQuery
Where Month([YourDateField]) = 8
I have a simple IIF statement to say if the actual date is blank, show me TBC. Otherwise, show me what the actual date is. I can successfully get the TBC. But I cannot get the actual date to show where I know there is a date. Any help is appreciated.
=IIF(Fields!VPSR_Actual_Date.Value = "", "TBC", Fields!VPSR_Actual_Date.Value)
I'd do a check if the column is null or zero string and then format the date.
=IIF(IsNothing(CStr(Fields!VPSR_Actual_Date.Value)) OR CStr(Fields!VPSR_Actual_Date.Value) ="", "TBC", Format(Fields!VPSR_Actual_Date.Value, "dd-MMM-yyyy"))
Hi I'm trying to build a report in ssrs which gives the output based on current weekending date where end day is saturday. I'm pulling my data from SSAS Cube and I have a weekending date field so I applied a filter in the query designer to get the current weekending date using a parameter I used this expression:
DateAdd("d",7-DatePart(DateInterval.Weekday,Today,FirstDayOfWeek.Sunday),Today)
When I'm executing my query, it throws an error saying the restriction imposed by the constrained flag in the STRTOSET function were violated.
Please let me know how can I fix this.
The error is thrown because you are passing a string that doesn't correspond with a valid member in your cube.
Note the Query Designer builds a MDX query based on the dimensions and members you select, this query uses the STRTOSET() function to convert your string parameter in a valid member.
...
STRTOSET(#CurrentWeekendDate,CONSTRAINED)
...
If you pass the current weekend date to your parameter it produces:
STRTOSET('2016-01-10',CONSTRAINED)
As 2016-01-10 is not a valid member in your Date dimension it throws the error.
You have to pass something like this depending on your cube:
[Date].[Date Key].&[2005-01-01T00:00:00]
So in SSRS you have to set your parameter to Text and use this expression:
CORRECT EXPRESSION:
="[200 Date].[Week Ending Date].&[" &
Format(
DateAdd("d",7-DatePart(DateInterval.Weekday,Today,FirstDayOfWeek.Sunday),Today),
"yyyy-MM-ddThh:mm:ss"
)
& "]"
UPDATE: If [Week Ending date] level doesn't include time:
="[Date].[Date Key].&[" &
Format(
DateAdd("d",7-DatePart(DateInterval.Weekday,Today,FirstDayOfWeek.Sunday),Today),
"yyyy-MM-dd"
)
& "]"
Go through this tutorial if you get stuck.
Let me know if this helps.
I have a report that uses date params (so have to be datetime in SSRS, which sucks to start with). When the user enters a date such as "5/1" it creates a DateTimeOffset data type and I can't find anyway to cast it to anything else, format it, or concatenate in a text box. I tried casting to a date to a string, etc. All I get is:
Conversion from type 'DateTimeOffset' to type 'String' is not valid. ('String' is replaced by anything I try to cast it to)
Surely there must be a way to have a text box show "From 5/1/2013 to 5/31/2013" when the user types "5/1" and "5/31" in the date field? Does Microsoft really think computer-literate people want to pick up the mouse to use their date picker instead of using tab?
Try the following expression:
="From " & Format(Parameters!Param1.Value.DateTime, "M/d/yyyy") & " to ..... etc"
To test this expression I've created a fresh report, added a DateTime parameter, and entered "5/1" in the textbox, hit enter. The report comes up with the following textbox:
From 1/5/2013 to ..... etc
For my locale, this is correct, because when entering DateTime values days are assumed to come before months. When the report is viewed the textbox will also update and show:
5-1-2013 0:00:00 +01:00
From this you should be able to extrapolate and use it for a second parameter as well, extending the expression to show the exact string you need in your report.
The Parameters!Param1.Value.DateTime helped when the user omits the year, but it broke down when the user decides to include the year. I couldn't get it to work under both conditions.
Try this.
Include the date parameter value as a field in your resultset. Your SQL might look like:
SELECT field1, field2, Convert(date, #FromDate) [FromDate_param] FROM table
Then you can create an expression in SSRS like:
="From " & Format(First(Fields!FromDate_param.Value), "M/d/yy")
I have a report with date and time (only an hour and minutes) parameters which are separate. The Date parameter is of type Date/Time, and the Time parameter is set as Text. I want to merge those two values into one because I want to pass a minimum number of arguments to the stored procedure. I tried to achieve that goal in many ways but SSRS returns an error for every attempt.
If I try to use expression like this:
=Format(FormatDateTime(Parameters!startDate.Value, DateFormat.ShortDate).ToString() + Parameters!startTime.Value, "dd/MM/yyyy HH:mm")
SSRS returns this error:
Error conterting data type nvarchar to datetime.
And when I tried to use Datetime.Parse like this:
=DateTime.Parse(Format(FormatDateTime(Parameters!startDate.Value, DateFormat.ShortDate).ToString() + Parameters!startTime.Value, "dd/MM/yyyy HH:mm"))
SSRS said:
The Value expression for the query parameter '#startDate' contains an error: The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
When I removed the FormatDateTime function I get yet another error:
The Value expression for the query parameter '#startDate' contains an error: Input string was not in a correct format.
Do you have any ideas how to write this expression correctly?
PS. I use SSRS 2008 R2.
This works for me:
=CDate(Format(Parameters!Date.Value, "yyyy-MM-dd") + " " + Parameters!Time.Value)
Didn't try and troubleshoot your specific examples, but they may be running into issues where you're not including the space between the date and time.
The above expression may be suitable for your report; don't know robust it would be in different locales.
You could also consider doing the concatenation/conversion in custom code if you need more flexibility.