access macro IsNull multiple variables - ms-access

If IsNull(delivery) = True Then
This code is running for one variable i.e delivery.
I have check isNull for three variable and I want code for that.
This code is for Access Macro.

Use an And or Or operator depending on the logic that you require, for example using And logic:
If IsNull(delivery) And IsNull(variable2) And IsNull(variable3) Then
' Do something if all three variables are null
End If
Alternatively, using Or logic:
If IsNull(delivery) Or IsNull(variable2) Or IsNull(variable3) Then
' Do something if any of the three variables are null
End If

Related

SSIS 2008: Conditional logic to use different sources in Data Flow Task

I have an SSIS 2008 package with data flow task using Task Factory Salesforce.com source, and in the WHERE clause is the below statement, which works fine.
WHERE SystemModstamp > <#User::dt_last_success>
I'd like to pull off a conditional 'IF #load_all_data=True THEN do not include the above WHERE clause, and if False then include it. I've been told that this is not possible in Salesforce Object Query Language (SOQL) to include that logic in the WHERE clause of the above query* , which means that I'll need two separate data sources: one with the current WHERE.., and one without.
I'd prefer not to copy-paste each data flow task, and the only different being the WHERE clause, to pull this off.
Question: What's the easiest way to pull off two sources based on logic with a parameter in a data flow task, using the same destination? Preferably without a JOIN that requires sorting.
Thanks in advance.
Jim
https://salesforce.stackexchange.com/questions/57277/ssis-package-connecting-to-salesforce-with-or-parameter-y
I'm not familiar with the TaskFactory's Salesforce.com source, but most SSIS things allow for the concept of Expressions to be applied to them. Looking at the documentation for SFDC and knowing the PW folks, surely they allow for this.
Create a Variable, LoadAllData of type boolean and set it to False
Create a second variable, of type string, called Query. You will then need to set the EvaluateAsExpression property to True and then use an expression like the following (note the double quotes are part of the Expression.
"SELECT MyCols FROM MyTable "
+ (#[User::LoadAllData]) ? "" : "WHERE SystemModstamp > <#User::dt_last_success>"
That will build the query of SELECT MyCols FROM MyTable for the full load, SELECT MyCols FROM MyTable WHERE SystemModstamp > <#User::dt_last_success> for the incremental load.
Once you verify the strings are working, as expected with the variable toggle, you then go into your data flow, right click on the SFDC source and under Expressions, there ought to be something that corresponds to the SalesForceQuery and you then assign as its value #[User::Query]
Tying this all together, you'd then use the /SET property when you run the package to flip the value of LoadAllData to True whenever you need the full load (which I assume is the exception and not the standard case).
dtexec /file ./SFDC.dtsx /Set \Package.Variables[User::LoadAllData].Properties[Value];1
^^^ That's approximate. I haven't tried to set a boolean from the command line so it might expect True, true or possibly TRUE. Quick experimentation on your part should reveal the specific syntax.

SSRS expression replace NULL with another field value

I need to write an SSRS expression to check and replace NULL field value with another field value. Can this be done?
=iif(isNothing(Fields!FV1.Value), Fields!FV2.Value, Fields!FV1.Value)
If you have to do it a bunch of times, you can also make a reusable function to avoid a lot of typing. Here's a solution modeled off of SQL's ISNULL function:
Right click on the Report Document and go to Report Properties.
Navigate to the Code tab and add the following function:
Public Function IsNull(input As Object, defaultValue As Object) As Object
Return IIf(input Is Nothing, defaultValue, input)
End Function
Note - Even though the custom code is expecting valid VB.NET code, you have to use the IIF Ternary operator.
Then you can use it in an expression like this:
=Code.IsNull(Fields!MyField.Value,0)

Crystal Reports Custom IsNull Function

I am trying to create a custom IsNull Function in Crystal Reports; the function must act the same way as the IsNull Function in MS SQL Server. I want to specify a field, and if the field is null, then it must be returned with a value I have specified.
IsNull({myField},0) or
IsNull({myField},'Hello World')
I have encountered that I have to create a separate function for number fields and a separate function for text fields. I also found that Crystal does not allow the use of standard functions inside of a custom function, for instance the ISNULL Function:
Function(NumberVar param, Numbervar setter)
IF ISNULL(param) THEN setter ELSE param
and
Function(StringVar param, StringVar setter)
IF param = NULL THEN setter ELSE param
Does anyone know how I can create a function like this in Crystal and a work around for the ISNULL inside of a custom function?
You can't pass a null value into a custom function, so it's pointless to use crystal's isnull function inside one. Only option is to write it like...
if isnull({myField}) then 0 else {myField}
I found this issue, in the formula editor there is a drop down in the header that indicates:
Exception for Nulls
Default values for nulls
Select the second one ( Default values for nulls)
I've encountered the same behavior, but I have yet to see a documented reason for this.
I would suggest that you use a SQL Expression:
//{%myField}
(
ISNULL({myField},'Hello World')
)
This worked for me:
if (isnull({dbvalue}) or ({dbvalue} ='')) then
"Display the required text"
else
{dbvalue}

RDLC Expression Extension Methods

Is it possible to write extension methods for expressions behind RDLC fields?
For example, let's say that I have a DateTime field in my datasource that may either have a valid value or may be null. I drag and drop a TextBox onto my RDLC and format its value using the ToShortDateString() method. This works fine for populated DateTime value, but this will also obviously throw an exception at runtime if I try to do a .ToShortDateString() on a NULL field.
I was wondering if I could write an extension method that I could use in my RDLC expressions so that when I'm dealing with ?DateTime values, I could call a method like .ConvertFromNullToEmptyString().
Of course there are other ways to work around this issue, but I was wondering if extension methods for use in RDLC expressions would be a possible approach to my business problem.
Thanks folks!
Yes, this is possible. You can either embed code directly in the report or include a custom assembly.
It is possible to use extension methods, but not AS extension methods on an instance of an object. You would have to call them as a static method call on the type of which they are a member. So instead of myDictionary.Values.Sum() -- calling the Sum method on the Values property of a dictionary instance -- you could use System.Linq.Enumerable.Sum(myDictionary.Values) -- passing the instance into the static Sum method of the Enumerable type (in this example, the report must reference the System.Core assembly). So yes, you can use methods that are also extensions, but (it appears anyway) not as extensions on a particular instance.
While I agree with Corina on the solution to the question, I believe a better solution can be reached without going the route she suggests, using built in expressions. In any case where you have a DateTime coming from SQL, you're correct, it can be null, however, you can easily test for this using an IIF statement (remember that the expressions are basically in VB) to check for null / nothing / empty and as long as it is something, run the desired operation, otherwise return blank. Just be careful, as the resulting type of the IIF will probably be string.
For example, let's say that I have a DateTime field in my datasource that may either have a valid value or may be null. I drag and drop a TextBox onto my RDLC and format its value using the ToShortDateString() method. This works fine for populated DateTime value, but this will also obviously throw an exception at runtime if I try to do a .ToShortDateString() on a NULL field.
There should be no need for a custom function in your case. Just use VB's If() ternary operator:
=If(Fields!MyDate.Value IsNot Nothing, Fields!MyDate.Value.ToShortDateString(), "N/A")
(Personally, I funnel my objects through AutoMapper and let it substitute null values with default values or objects, so that I don't have to deal with null values in the report at all).
It should be mentioned, that the If(condition, true_part, false_part) ternary operator should (with one I) be preferred over the IIf(condition, true_part, false_part) function (with two I's) in most cases.
The If() ternary operator will short-circuit evaluate only the part that corresponds to condition outcome (e.g. a condition that is True will only evaluate the true_part).
The IIf() function will always evaluate the condition and both parts, because it is just a function call and all parameters of the function will be evaluated before the call.

Problem evaluating NULL in an IIF statement (Access)

Item in the recordset rstImportData("Flat Size") is = Null
With that, given the following statement:
IIF(IsNull(rstImportData("Flat Size")), Null, cstr(rstImportData("Flat Size")))
Result: Throws error 94: Invalid use of Null
If I change the statement by removing the type conversion upon a false comparison:
IIF(IsNull(rstImportData("Flat Size")), Null, 0)
Result: Null
It returns Null as it should have the first time. It appears that I cannot do a type conversion in an IIF if the value passed in should ever be null even if it passes an IIF test, it still attempts to evaluate it at both the true and false answer. The only reason I'm using IIF like this is because I have a 25 line comparison to compare data from an Import against a matching record in a database to see if I need to append the prior to history.
Any thoughts? The way data is imported there will be null dates and where the spreadsheet import is in a string format I must convert either side to the other to compare the values properly but if either side is null this exception occurs :(
EDIT
Example of why I was using IIF (and considering using a universal function)
If master("one") <> import("one") Or _
master("two") <> import("two") Or _
master("date") <> import("date") Or _ //import("date") comes from a spreadsheet, it comes in as string, CAN be a null value
master("qty") <> import("qty") Or _ //import("qty") comes from spreadsheet, comes in as a string can CAN be null
master("etc") <> import("etc") Then
....stuff....
End If
This code expands for roughly 20 columns to compare in the database. I would prefer to check as part of the statement. I can think of a bunch of solutions but they involve adding much more code. If that is the case power to it, however I'm not one to give in so easily.
Options I see are
Creating temp vars to do the work prior to comparing and using these new vars instead of the recordset
Creating an object to pass the record into to preformat and work with, though extra work would provide this functionality to each import type since there are different files with similar fields
I'm here for ideas, and I'm open to any interesting pieces that can be thrown my way as I get to decide how to do it I'm looking for the most reusable approach.
The simple expedient of changing the value to a string helps tremendously. The trick is that trimming a string which is NULL will get a null string. Which can then be operated on as if it wasn't a database null.
I frequently use the form:
CInt("0" & Trim(SomeVariant & " "))
To get a valid number without having to go through a bunch of hijinks. The null is a nonentity for this problem.
The behavior you described is the standard way IIf operates under VBA. This is part of what Access 2003 Help says about it:
"IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True."
However, if you use an IIf statement in a query, evaluation short circuits after truepart when expr is True --- falsepart is not evaluated in that case. Unfortunately this information is not useful for you ... unless you can incorporate a query into your comparison.
I don't know of any other way to avoid your error with IIf. I would try appending the Excel data into a table whose structure matches that of the table you will compare against, thereby eliminating the need to do a string conversion at the same time you do the comparison.