Detecting NULL dates and showing empty string in SSRS - sql-server-2005

I'm trying to format some cells in a Reporting Services report that will contain DateTime? values - or not.
If the underlying data has a NULL for that DateTime?, I'd like to show nothing (empty cell) - and if that data source contains a value, I'd like to show the date in short date format (dd.MM.yyyy in my locale).
So I tried to put this formula into the relevant SSRS cells
=FormatDateTime(Fields!DatumBSE.Value, 2)
but now I'm getting 01.01.0001 for all NULL dates....
I can't seem to wrap my head around how to do this in a SSRS (VB) formula.... I tried using IsNothing() but that doesn't seems to really help - I can detect a NULL, but how to I tell the cell to show an empty string in that case?
Solution:
I ended up using this function:
=IIF(IsNothing(Fields!DatumBSE.Value), "", FormatDateTime(Fields!DatumBSE.Value, 2))
Seems to work just fine for me now.

I just tested the following expression and it replaced the null date with an empty string:
=IIF(Fields!DatumBSE.Value is nothing, nothing, FormatDateTime(Fields!DatumBSE.Value, 2))
The other suggestion that I would make is that you could format the date to the correct format in the report dataset by placing a CASE expression around the date value.

use a code like this:
If(isNull([date field]),Null, elsequote)

Related

Crystal Reports - Comparing two numeric field values with a formula

I thought this would have been a simple task, I want to change the font colour of a field in a Crystal Report if it differs from another field value. Essentially I have two numeric fields and want to change the font to red if they are different.
I have used the Format Editor>Font>Color formula method. I have tried the following code/s ...
if ToNumber({Petty_Cash.PettyCashandMoneyIntroduced}) = ToNumber({Petty_Cash.LessTotalPaymentsByPettyCash}) Then crBlack Else CrRed;
if {Petty_Cash.PettyCashandMoneyIntroduced} <> {Petty_Cash.LessTotalPaymentsByPettyCash} Then crRed Else CrBlack;
Neither of these will work, if I add a numeric value it will work....
if {Petty_Cash.PettyCashandMoneyIntroduced} >=90 Then crBlack Else CrRed;
I'm hoping it's something simple that I have overlooked.
Any ideas please?

Why is the output for my datediff expression to return a number of days bracketed?

I have written the following expression to give me the number of days between a date and today.
=IIF(Fields!First_Check_Start_Date.Value = nothing,nothing,datediff("d",Today,Fields!First_Check_Start_Date.Value))
The output is correct but is bracketing the number
ie. (292) instead of 292
Any help as to why this is
if you are using text box to display your result, check what is the type of your text box. Make it as number and look for it's format and set to correct
Else you could also format like below
=IIF(Fields!First_Check_Start_Date.Value = nothing,nothing,Format(datediff("d",Today,Fields!First_Check_Start_Date.Value),"##"))
So it appears that whilst viewing in SSRS Report builder the numbers are bracketed (292), however once export to either csv or excel the bracket disappears and is replaced bi a minus -292 which is correct
Thanks

How to Fix #Error When Calculating a DateDiff With an IIF Statement in SSRS

I'm creating a report in Reporting Services to display time-spans for classroom sessions in our program. One column that was requested is to show the total number of hours between the start and end time of one session. I used a DATEDIFF function showing the DateInterval in hours as the total hours in one time-span, but I get a #Error returned for the blank values that haven't been assigned a begin or end time.
I added an IIF statement to mark the values that are blank as "TBA", but that didn't work. Since I'm casting a string to a datetime value, I enclosed the DATEDIFF statement in a CStr function, but that also isn't working. Lastly, I did the simple thing and set the text box to display a Number value since it's returning the total number of hours, but of course, that didn't work either. My code is as follows:
=IIF(Fields!BeginTime.Value = "", "TBA", CStr(DateDiff(DateInterval.Hour, Fields!BeginTime.Value, Fields!EndTime.Value)))
It's supposed to show that "TBA" value in the blank spots, but I still get a #Error. The total hours are coming up fine for the values that aren't blank, however. I checked the value in the dataset to see if it's returning a blank or a NULL-labeled value, and it is returning a blank value.
I believe the issue is arising in the conditional statement. If Fields!BeginTime.Value is a date datatype, comparing it to "" will likely result in the error you're getting. I suggest using the IsNothing function or just checking if the field is nothing. The two options are as follows.
=IIF(IsNothing(Fields!BeginTime.Value), ...
Or...
=IIF(Fields!BeginTime.Value Is Nothing, ...
With that said, you shouldn't need to use the CStr as DateDiff will return an integer value. Your textbox should be set to Default or some text variant to prevent errors there. The expression will return either an integer or string so a number format on the textbox will not work.
Additionally, if you're having the same issue when there is no EndTime, you may want to add an OR to the conditional to fix that.
=IIF(IsNothing(Fields!BeginTime.Value) OR IsNothing(Fields!EndTime.Value), ...

Google Script Sheets API - default number format

It looks like google sheets is making the same mistake as Excel, by "thinking ahead" and converting the value "1.1.1" to 2001.01.01 when doing sheet.appendRow. I have tried to set the number format of the column in charge to "#" (which should be plain text) before inserting rows - but looks ineffective. On the other hand doing the same after inserts is also ineffective, as the content is already "date".
Adding ' before is working, but it is not what I need.
Is there any way to give a default format or to disable such automatic conversion (from google script)?
I have a cell in which a form deposits a variable number of values seperated by a comma such as: " 1, 2, 4, 6 " etc - when there are only three answers, Google "helps" me by converting the value into a date object. But it's supposed to be a list of choices...
It's not pretty, but I've managed a workaround by using .getDisplayValue instead of .getValue - it does change the cell value into a string, so if you need to do further manipulations that are dependent on the value being a number or something, obviously, this fails.
I overwrite the value for the problem cell in my array before passing it to .appendRow
//getting the values
var values = s.getRange(row,1,1,lastCol).getValues()[0];
//brute force crushing of problem value
values[5] = s.getRange(row,6).getDisplayValue();

Date format issue in SSRS

I have an issue with date format in my SSRS. I am saving date from DateTimePicker to database. From there I am taking display in my datagridview using following
dgv.items(0,2).value=Format(Cdate(dsSaver.tblInv.rows(0).items(0)),"dd-MMM-yyyy")
This displays it correctly (04-Nov-2011) but when I take date from the same database to my SSRS using
="Dated: " &Format(cdate(Fields!InvDate.Value),"dd-MMM-yyyy")
It displays it like 11-Apr-2011.
I have tested all winforms fare displaying it right but all SSRS are displaying it wrong.
Please advise.
A couple of things are going on here. The date is being saved appropriately but is being displayed incorrectly due to your formatting options. This line is quite problematic:
="Dated: " & Format(cdate(Fields!InvDate.Value), "dd-MMM-yyyy")
CDate takes a value, generally a string, and converts it to a date, which you are then taking and formatting back into a string. Now, by default reports are set to have their Language property set to English (United States) so the CDate function is taking the string representation of the date 04-Nov-2011 to be 04/11/2011 which it is then converting, using the US format of MM-dd-yyyy (not the Pakistani one) into being the date 11-Apr-2011 because it thinks the month comes first.
So, you should change your Language setting of your report to =User!Language so that it supports whatever the user's language is and will format things appropriately. This may be enough to make your expression work.
Regardless, if Fields!InvDate.Value is being supplied as a date field (as it should be) there is no need for the CDate function and this should work:
="Dated: " & Format(Fields!InvDate.Value, "dd-MMM-yyyy")
There is also the FormatDateTime function but unfortunately it doesn't support the format you want to use.
Have you looked at the RDLC options for Formatting a Report: Format the Date?