Handling NULL Dates in SSRS - sql

We have a SSRS Report. This report have a field called Actual Date. Whenever this field is null, the report need to show "N/A". To handle this, I have done as below.
="Report End Date: "= IIF(IsNothing(CSTR(First(Fields!Actual_Max_Date.Value, "dataset1"))), "N/A", CSTR(First(Fields!Actual_Max_Date.Value, "dataset1")))
But I always get False as Result. anything wrong in the above expression? Also is it possible to add custom color to the string "N/A"?
Thanks for the help

Use String.IsNullOrEmpty() instead of IsNothing()
and
1st part of your expression (="Report End Date: "=IIF....)
should be ="Report End Date: " + (IIF....))
Example (My report parameter is datetime picker):
="Report End Date: " + (IIF(String.IsNullOrEmpty(Parameters!ReportParameter1.Value),"N/A",Parameters!ReportParameter1.Value))

Related

Invalid use of Null Access VBA even when IIF condition states not to check

I am trying to create a date query so that null is returned if there is no date and only date value from date/time is pulled if there is date and time value
IIf(Nz(rst("DateAssigned"), "") = "", "NULL", "'" & DateValue(rst("DateAssigned")) & "'")
Now, I get the error:
Run time error: '94' Invalid use of Null
When the rst("DateAssigned") value is null. I know this is coming from the DateValue function. Why is it trying to parse the DateValue when the value is null?
Does vba parse everything in the entire statement without checking the IIF condition? Or did I make a mistake?
I think you are right: VBA parses the entire IIF statement first before run it. Try this in immediate window:
?IIf(1 = 1, "NULL", DateValue(NULL))
You will get the same error.
I suggest you use the regular IF statment (if you do not want to use it inside of a query)
The answer to your questions
Why is it trying to parse the DateValue when the value is null?
and
Does vba parse everything in the entire statement without checking the IIF condition? Or did I make a mistake?
is:
Because DateValue is used as an argument for a parameter of the Iif procedure.
In general:
A procedure can only be executed when all its parameters are known. Therefore, procedures that are given as arguments are executed first.
You must make sure, that no invalid values are passed to DateValue:
IIf(IsNull(rst("DateAssigned"), "Null", "'" & DateValue(Nz(rst("DateAssigned"), Date()) & "'")
But is would be more straight forward to use Format:
IIf(IsNull(rst("DateAssigned")), "NULL", Format(rst("DateAssigned"), "Short Date"))

Date in Text format- Birt

I need to display a text date like " August, 2018" if it is coming like "08-02-2018".
So, I have written this
" MONTHNAME(MAIL_DATE + 12 DAYS)||', '||YEAR(MAIL_DATE + 12 DAYS) as DateInText " wherein MAIL_DATE is today's date.
And, I have mapped in Birt like row["DateInText "], but I am not getting the value as expected like "August, 2018" .
You can make use of in built BIRT functions to achieve this.
In the detail row of the table, right click on the cell and go to "Edit Value/Expression.."
In the expression you can try this :
BirtDateTime.month(new Date(dataSetRow["DateInText"]),2) + ", " + BirtDateTime.year(new Date(dataSetRow["DateInText"]));
I hope this works.
Thank You

How do I format the date to include the week number?

I am using Microsoft Business Intelligence Development Studio 2012 trying to create a calculated field that will give me the Month and Week number of a field with the name 'createdon'.
I am new to SQL and after some research this is the code that I have come up with.
=Format(Fields!createdon.Value, "MMMM") & " Week " & (Int(DateDiff("d",DateSerial(Year(Fields!createdon.Value),Month(Fields!createdon.Value),1), Fields!FullDateAlternateKey.Value)/7)+1).ToString
But I am getting the error:
"The Field expression for the dataset 'Dataset1' refers to the field
'FullDateAlternateKey'. Report item expressions can only refer to
fields within the current datasetscop or, if inside an aggregate, the
specified dataset scope. Letters in the names of fields my use the
correct case.
I know this means that "FullDateAlternateKey" is not a valid field name, but I do not know what field name to substitute instead to correct this expression. Does anyone with more experience have any ideas as to how I can correct this?
Ideally, I would like it formatted to have a column that shows "week ending in ".
So any dates from 9/26/2015 to 10/2/2015 would say "Week of 10/2/2015"
Try this:
="Month: " & Datepart("m", Fields!createdon.Value) & " Week: " &
Datepart(DateInterval.WeekOfYear,Fields!createdon.Value)
You will get the following: Month: 10 Week: 43
Edit your question and add a example of the desired result in order to help you with the specific format.
Update:
Try this:
="Today: " & Format(Fields!createdon.Value,"dd/M/yyyy") & "Week Of: " & Format(
DATEADD("d" ,7-DATEPART(DateInterval.WeekDay,Fields!createdon.Value,FirstDayOfWeek.Monday),Fields!createdon.Value),
"dd/M/yyyy")
It will show: Today: 19/10/2015 Week Of: 25/10/2015

Can we allow user to only select one parameter at a time in SSRS

I have three date columns. My report has 6 parameters: start and end date range for all three columns. Currently user has to select all date range but what if I want to allow user to only select one date range at a time. I cannot do "allow NULL values" option in the parameter because that see it as a field containing null value. I don't think it's possible to allow user to select only one parameter at a time so I'm trying an approach where there will be three parameters: one will consists of date field names. And rest two are based on date range of the field that is select from previous parameter. For example user selects a date field name from first and then date parameters will be cascaded and grab a value of date field based on the date field name that is selected in previous parameter. But I'm not sure exactly how to approach this. Any ideas?
I do that in some of my reports. The first parameter is "Does the range apply to A, B, or C" and the second and third parameters are the start and end data respectively. Well, I use integers, but dates should work the same as long as you format them.
The way it works, is you set the query in your dataset to be a function, and build it as mostly a quote but with the parameter values substituted in. A typical one might be
= "SELECT * FROM dbo.Trips WHERE " + Parameters!WhatField.Value + " between '" + FormatDateTime(Parameters!StartDate.Value, dateformat.shortdate) + "' and '" + FormatDateTime(Parameters!EndDate.Value, dateformat.shortdate) + "'"
Your parameter "WhatField" is a drop down list with 3 permitted values, make the value be the field name and the display be what your user wants to see as a description of the field.
I think you have to set the query for delayed evaluation somewhere (but I can't spot where right now, so maybe I'm mis-remembering), and you should set default values for your parameters that don't crash your report, but other than that it's fairly straightforward.
Oh, and to make the query a function it's just like a text query but hit the button to the right of the text box - it has a "fx" on it
If you need an even more complex query, you can put the whole query text in code (off the report properties) and call that function from the "fx" button to generate your query string.

converting date format in an access table with sql update

I have a problem converting dates while updating an SQL table in VB under access: here is my code:
'Excel format date conversion
strSQL = "UPDATE tblBlotterINTLControl " & _
"SET tblBlotterINTLControl.TradeDate = CVDate(TradeDate), " & _
"tblBlotterINTLControl.SettleDate = CVDate(SettleDate);"
DoCmd.RunSQL strSQL
I obtain an error for each row: "type conversion error"
I have my tables in the right format though, please help thanks
EDIT:
I have to say that a SELECT request works but an UPDATE request doesn't! why? how?
What are the data types of the TradeDate and SettleDate fields in the Access table tblBlotterINTLControl?
SELECT TypeName(TradeDate) AS TypeOfTradeDate, TypeName(SettleDate) AS TypeOfSettleDate
FROM tblBlotterINTLControl;
Please paste that query into SQL View of a new query in Access, run it and show us what you get back.
The reason I asked is because the SET statements in your UPDATE query puzzle me.
SET tblBlotterINTLControl.TradeDate = CVDate(TradeDate)
If the TradeDate field is Date/Time datatype, using the CVDate() function on it doesn't accomplish anything.
If the TradeDate field is text datatype, CVDate() will give you a variant date, but you can't store that Date/Time value back to your text field.
Maybe you would be better off using the Format() function. Here is a sample I copied from the Immediate Window:
? Format("2011/01/01", "d mmm yyyy")
1 Jan 2011
Try CDate instead of CVDate.
CVDate actually returns a Variant of type vbDate and is only around for backwards comparability. Maybe that's what causing the problems.