In a Data Flow, I have an Derived Column task. In the expression for one of the columns, I have the following expression:
[siteid] == "100" ? "1101" : [siteid] == "110" ? "1001" : [siteid] == "120" ? "2101" : [siteid] == "140" ? "1102" : [siteid] == "210" ? "2001" : [siteid] == "310" ? "3001" : [siteid]
This works just fine. However, I intend to reuse this in at least a dozen other places so I want to store this to a variable and use the variable in the Derived Column instead of the hard-coded expression. When I attempt to create a variable, using the expression above, I get a syntax error saying 'siteid' is not defined. I guess this makes sense because it isn't. But how can I get this the expression to work by using a variable? It seems like I need some sort of way to tell it that 'siteid' will be the column containing the data I want to apply the expression to.
You can't use column names in variable expressions. I'm afraid there is no way to easily "clone" this logic in SSIS.
I would suggest, however, that you don't attempt to clone hard-coded logic like this. Construct a reference table and use a Lookup component to fetch the value. That way, if your "case" statement ever changes, you only need to do one modification - you don't need to hunt down everywhere this logic gets used. And configuration of the Lookup is pretty drag and drop easy.
Related
I am trying to change the background color of a row where the value is more than 1 with an expression. I have copied the following code from an earlier thread related to this issue but is not working for me.
= IIF(fields!OpenstaandeTijdInUren.value = >1, "Orange")
When I try to save it I get the following error statement:
instead of "fields" and "value" you need to capitalise the v and f, so the correct expression would be =IIF(Fields!OpenstaandeTijdInUren.Value >=1, "Orange"), although from the wording of your question, you might want to use > instead of >=. SSRS expressions are case sensitive. You should probably also put something in the false side of the check, maybe "Transparent".
=IIF(Fields!OpenstaandeTijdInUren.Value >=1, "Orange","Transparent")
Can you try this -
=IIF(Fields!OpenstaandeTijdInUren.Value > 1, "Orange", "No Color")
I have a database which tracks employee QA. I'd like to be able to search by a single Staff Member, a whole team, or a Unit. I have three controls that correspond to those fields and only one can ever have a value at once. In my quesry I'd like to have threee expressions that will limit my results by one of those three fields. I'm adding just one to start and I've hit a problem.
I found this https://www.acuitytraining.co.uk/microsoft-training-courses/access/if-statements/ which seems to do what I want. Here is the code I'm trying.
IIf(IsNull([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect]),
[UserLogin] Like "*",[UserLogin]=[Forms]![MainMenu]![btnManagersMenu].
[Form]![cmbStaffSelect])
Which works fine if the control has a value. (condition is false) If the dropdown has no value (condition is true) I get zero results. I suspect the problem lies with the Like "*" on my UserLogin field. Here is my query wizard and the buildler wizard for the IIF expression
Can anyone see why I'm not getting any results for the dropdown control being empty. To my thinking this should give me an unfiltered list of results. I have double checked my data and there are 137 records that should appear if I'm not limited by the staff selection.
The short version of this is if cmbStaffSelect has a value I want my records limited by that value. If cmbStaffSelect is blank I want to get all records.
Keep in mind that the iif function will always evaluate both the then and else arguments, before returning the appropriate value depending on the value returned when evaluating the supplied test expression.
As such, if either the then or else arguments have the potential to error when evaluated (regardless of the result of the evaluation of the test expression), then the iif expression has the potential to error.
As an alternative, you could use the Nz function to achieve the same result:
[UserLogin] LIKE Nz([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect],"*")
Perhaps your IsNull([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect]) is always returning false because cmbStaffSelect might be equal to empty string?
Try something like this:
IIf(Trim([Forms]![MainMenu]![btnManagersMenu].[Form]![cmbStaffSelect] & "") = "",
[UserLogin] Like "*",[UserLogin]=[Forms]![MainMenu]![btnManagersMenu].
[Form]![cmbStaffSelect])
This checks to see if the cmbStaffSelect is "" ... if cmbStaffSelect is null - it converts it to "" by appending an "" to the null value.
I believe your hunch is exactly correct. If you want your query result to return the * symbol for the UserLogin field; then alter your IIF statement to be: [UserLogin] = "*"
=switch(
Fields!HEORG_REFNO.Value=7535,"public",
Fields!HEORG_REFNO.Value=7539,"public",
Fields!HEORG_REFNO.Value=7609,"public",
Fields!HEORG_REFNO.Value=7541,"public",
true,"private"
)
I want to group my result based on weather the clinic is private or public, hence to do so i am trying to create a new field based on the above switch condition.
if(heorg_refno=7539 or heorg_refno= 7609 or heorg_refno=7541) then it would be public otherwise the clinic should be private.
Any suggestions what am i doing wrong in the switch statement.
One reason for this could be that Fields!HEORG_REFNO.Value does not actually contain integer values, but String values. In that case you'd have to compare against strings:
=Switch
(
Fields!HEORG_REFNO.Value="7535","public",
Fields!HEORG_REFNO.Value="7539","public",
Fields!HEORG_REFNO.Value="7609","public",
Fields!HEORG_REFNO.Value="7541","public",
true, "private"
)
You need to check the type for the HEORG_REFNO column in the SSRS dataset.
Also in my experience it is a good idea for stuff like this to create a fake column in your data set which you can filter over instead of putting too much stuff into expressions.
The latter leads to confusion because sooner or later.
I am trying to convert a time within an IIF statement.
I have a field with a value of: 2013-10-15 01:00:00.0000000. I am trying to convert that to "01:00" and then produce 1 of 2 results based on the conversion.
I have tried both using a case when statement which does not seem to work.
I have also tried using like "*01:00*" which also does not work. Currently, this is what I'm attempting to do, but it seem that I'm not going about this the right way:
=iif(Fields!TEST1.VALUE LIKE ("*01:00:00.0000000*"), "TRUE", "NOT TRUE")
Looking strictly at what you're trying to do, with an SSRS expression you need to use InStr to check for a substring in a larger string:
=IIf(InStr(Fields!TEST1.Value, "01:00:") > 0, True, False)
This works fine on your example row and another test case:
However, we know very little about your data - is the underlying data actually a string or a datetime?
If your data is datetime, you can use a different approach:
=IIf(Hour(Fields!TEST1.Value) = 1 and Minute(Fields!TEST1.Value) = 0
, True
, False)
Or even:
=IIf(Fields!TEST1.Value.ToString("HH:mm") = "01:00"
, True
, False)
If possible, I would consider datetime functions if at all possible as they are closest to the intent of what you seem to be trying to achieve.
I have a SSIS package that I am programming and my script component won't allow null column inputs. I have checked the box to keep nulls in the flat file source component. My program is running well until my script component where I get the error "The column has a null value" (super vague, I know). The column currently throwing the error is an "int" valued column and is used for aggregations in my script.
I could make the null values 0s or to say "NULL" but I'd prefer to just leave them blank.
I am using SQL Server BIDS 2008.
So because SSIS deals with the databases so much and doesn't want to spend a lot of time differentiating between DB NULL and C# NULL, they create boolean properties for each input column in the Buffer with the naming convention (columnname)_IsNull. You can read more about that on MSDN.
So you have to use those buffer columns to determine whether the value is null and then doing whatever you're trying to do with that column in the component.
So something like
if (!Row.MyColumn_IsNull) {
//do something }
else {
//do something else, or nothing, etc.
}
While Kyle's answer is very sufficient, I used a different method that is working just fine. I used the ternary for c#.
Value = Value_IsNull ? True Value : False Value;
Row.rowname = Row.rowname_IsNull ? 0 : Row.rowname;
This changed the value of my null integer columns to 0 if they were null coming into my script. Otherwise, it retained the value.
Is your error occurring in the C# code somewhere? It gets a little maddening at times when you have a database column with the datatype int, and it allows nulls. In C# land you have to use the int? as apposed to int when you need to accept nulls. Otherwise the approaches mentioned already are a good way to go.