Comparing a time value with a value in ssis - tsql

I would like to use such an expression in dereived column, but it remains red (it is not accepted):
(DT_DBTIME) [Datum] =="00:00:00" ? 1 : 2
(if time part of variable [Datum] = "00:00:00" then 1 else 2)

You can't compare DT_DBTIME and DT_WSTR type. Try to cast data from DT_WSTR to DT_DBTIME type:
(DT_DBTIME) [Datum] == (DT_DBTIME)"00:00:00" ? 1 : 2

Related

How to identify and convert a series of numbers in DataStage?

I need to identify the values in a field which are of 9 series and greater than or equal to 99999 and convert them to 0s in DataStage i.e atleast first 5bytes of the field are 9s. Here are some examples to explain the situation better
999.00 - Don't convert
9999.00- Don't convert
99999.00- Convert to 0
999991.00-Convert to 0
100000.00- Don't convert
999999.00- Convert to 0
123456.00-Don't convert
9999999.00-Convert to 0
1999999.00-Don't convert
1000000.00-Don't convert
Right now i have If Convert('9','', Trim(Trim(Field(NullToZero(AMT),'.',1)),'0','L')) = '' Then 0. This converts any 9s but our goal is to convert 9s of 99999 and greater only. Please help with solution
Use Field() function to work with just the digits to the left of the decimal placeholder. Test that this value has at least five characters, and that they are all "9".
If Len(Field(AMT,".",1,1) >= 5 And Convert("9","",Field(AMT,".",1,1)) = "" Then 0 Else AMT
Even better would be to resolve the Field() function into a stage variable, so that it's not executed twice, and use that stage variable in the expression.

Passing hashset itself as parameter for reduce in swift

Given a hashset h = [1,2,3,4,5] for example, the purpose is to count the number of unique element i such that h.contains(i+1).
I can write down swift code using reduce() as
h.reduce(0,{h.contains($1+1) ? $0 + 1 : $0})
But what if h is an array containing duplicates instead of a hashset? I first need to convert it into hashset and then using the above expression:
Set(h).reduce(0,{Set(h).contains($1+1) ? $0 + 1 : $0})
But in this way we calculated Set(h).count + 1 times of Set(h) as pointed out by #carpsen90, is there any way to write the code like
Set(h).reduce(0,{self.contains($1+1) ? $0 + 1 : $0})
without using a temporary variable to store Set(h)?
Every time you call Set(h) a new set is calculated, so in your example Set(h).reduce(0,{Set(h).contains($1+1) ? $0 + 1 : $0}) , Set(h) will be calculated h.count + 1 times. Having a variable let set = Set(h) is the way to go here :
let set = Set(h)
let result = set.reduce(0) {set.contains($1+1) ? $0 + 1 : $0}
He is an alternative way of getting the desired result :
Let's create a dictionary that indicates wether a number has appeared in h:
var dict = [Int: Bool].init(minimumCapacity: h.count)
for x in h {
if dict[x] == nil {
dict[x] = true
}
}
And then, for each h element, check that its successor appears in the dictionary :
var count = 0
for entry in dict {
if dict[entry.key + 1] == true {
count += 1
}
}
And you could check the result :
print(count) //4
The problem here is that your array might contain duplicates and to filter the duplicates the easiest way is to convert it into the Set. And the correct way to do that is to save the set in a new variable hence it is unavoidable.
Though you can still use the reduce method without converting your array into a set like this:
var tempH = [Int]()
let c = h.reduce(0) { (result, item) in
if (!tempH.contains(item)) {
tempH.append(item)
return h.contains(item+1) ? (result + 1) : result
}
else {return result}
}
But, as you can notice in above code, we have to use a temporary array to track our duplicates. Hence an extra variable seems unavoidable here. Though no Sets are being used in above code.

Tableau mixing aggregate and non-aggregate results error

I have a problem creating a calculated field in Tableau. I have data like so:
ID ... Status Step1 Step2 Step3
1 ... Accepted 1 1 1
2 ... Waiting 1 0 0
3 ... Discard 0 0 0
4 ... Waiting 1 1 0
...
I would like to create a calculated column that will give me the name of the last Step, but only when status is 'Accepted'. Otherwise I want the status. The syntax is quite easy, it looks like this:
IF [Status] = 'Accepted' THEN (
IF [Step3] = 1 THEN 'Step3' ELSEIF [STEP2] = 1 THEN 'Step2' ELSEIF [STEP1] = '1' THEN 'Step1' ELSE 'Step0')
ELSE [Status]
The problem is that the column 'Status' is a Dimension and the 'Step' statuses come from Measure. So they are AGG(Step1), AGG(Step2),...
I guess that is the reason I get this error:
Cannot mix aggregate and non-aggregate comparisons or results in 'IF' expressions.
I am not very familiar with Tableau. Any idea how I can solve this?
Solution:
Just use function ATTR that will make the non-aggregate function (Status) into an aggregate one. Then it is possible to combine them and the calculation is working.
IF ATTR([Status]) = 'Accepted' THEN (
IF [Step3] = 1 THEN 'Step3' ELSEIF [STEP2] = 1 THEN 'Step2' ELSEIF [STEP1] = '1' THEN 'Step1' ELSE 'Step0')
ELSE ATTR([Status])
Tableau automatically interprets numeric values as measures. It appears though that in your case they are a boolean (0 for false, 1 for true) and really ought to be dimensions.
Convert Step 1, Step 2, and Step 3 to dimensions. Highlight the fields, right click, and choose Convert to Dimension.

iReport Variable for last Record

I have some records like this:
Datetime | Type |
2012-02-23 22:00:11 1
2012-02-23 22:02:14 2
2012-02-23 22:03:56 1
2012-02-23 22:04:11 1
2012-02-23 22:33:21 2
....
I will generate a list which shows:
The Datetime field
and, if Type = 2, the time difference between Last type 1 and actual Type2 Record.
Formatted with HH:MM:SS
Example for the above mentionend Data:
Datetime | Type | Diff
2012-02-23 22:00:11 1
2012-02-23 22:02:14 2 00:02:03 (Diff to 22:00:11)
2012-02-23 22:03:56 1
2012-02-23 22:04:11 1
2012-02-23 22:33:21 2 00:29:25 (Diff to 22:03:56)
I tried to use Variables in a different way.
But, as so often recently, unsuccesfull :-)
(i´m usinfg iReport 4.5.0)
Any ideas ?
thx Christian
First, create a variable $V{Diff} that calculates the difference between $F{Datetime} for all rows. This gives you the values you want (and a bunch that you don't need).
Second, only display $V{Diff} when $F{Type} equals 2.
But it's the details that make it fun. That variable is not entirely obvious in JasperReports. You actually need two variables, and they have to be defined in the correct order.
$V{Diff} Expression: $F{adate}.getTime() - $V{LastType1Date}
$V{LastType1Date} Expresion: ($F{type}.intValue() == 1) ? $F{adate}.getTime() : $V{LastType1Date}
Then the print when expression is easy: $F{type}.intValue() == 2 And you get what you need:
I have ignored the interval formatting, but I think this solves the key issues for you. You just need to transform the milliseconds into the format you want.
Try putting this in your variable expression (located in the variable's properties)
$F{Datetime}.equals($F{type}.equals(2))-$F{Datetime}.equals($F{type}.equals(1))
Create a Date variable called lastType1DateTime and for the variable expression put:
($F{Type} == 1) ? $F{DateTime} : $V{lastType1DateTime}
This variable will always hold the last type 1 date. Then simply do your diff in the detail field for type 2 rows.

double to int and comparison

I have a textfield and want to get the value stored as double and also compare whether it is between 2 and 20
double numOfYears = [[numOfYearsFld text] doubleValue];
Please let me know if the code above is correct and how can i compare/check between 2 and 20, since it is double ?
Yes, while your text field contains valid number your code to get its double value is OK (if field does not contain valid number your code will return 0).
Checking if your value is between 2 and 20 does not differ from what you would do in case you had integer (or any other plain number type):
if (numOfYears >= 2 && numOfYears <=20){
// check passed
}