concatenate column using derived column in ssis - ssis

I have asked this question before and I believed to have got the correct answer but i didnt.
What I am trying to achieve is Column 5:
Column 1 Columns 2 Column 3 Column 4 Column 5
A B NULL D A|B|D
B C B|C
NULL D NULL NULL D
I used a derived column:
(DT_STR,50,1252)((Column1 == "" ? "" : Column1 + "|") + (Column2 == "" ? "" : Column2 + "|") + (Column3 == "" ? "" : Column3 + "|") + (Column4 == "" ? "" : Column4))
But I ended with:
Column 1 Columns 2 Column 3 Column 4 Column 5
A NULL NULL D NULL
If I get NULL the overall answer is NULL

Try this:
(DT_STR,50,1252)((Column1 == "" || isnull(Column1) ? "" : Column1 + "|") +
(Column2 == "" || isnull(Column2) ? "" : Column2 + "|") +
(Column3 == "" || isnull(Column3) ? "" : Column3 + "|") +
(Column4 == "" || isnull(Column4) ? "" : Column4))

===
Hi Try using
ISNULL(Value) ? " " : Value
for each column
Mario

Related

Shorten if Statement Actionscript 3

I just started learning actionscript and I'm wondering how could I shorten this if statement
if (txtInputTemp.charAt(track - 1) == "a" || txtInputTemp.charAt(track - 1) == "b" || txtInputTemp.charAt(track - 1) == "c" || txtInputTemp.charAt(track - 1) == "d" || txtInputTemp.charAt(track - 1) == "e" || txtInputTemp.charAt(track - 1) == "f" || txtInputTemp.charAt(track - 1) == "g" || txtInputTemp.charAt(track - 1) == "h" || txtInputTemp.charAt(track - 1) == "i" || txtInputTemp.charAt(track - 1) == "j" || txtInputTemp.charAt(track - 1) == "k" || txtInputTemp.charAt(track - 1) == "l" || txtInputTemp.charAt(track - 1) == "m" || txtInputTemp.charAt(track - 1) == "n" || txtInputTemp.charAt(track - 1) == "o" || txtInputTemp.charAt(track - 1) == "p" || txtInputTemp.charAt(track - 1) == "q" || txtInputTemp.charAt(track - 1) == "r" || txtInputTemp.charAt(track - 1) == "s" || txtInputTemp.charAt(track - 1) == "t" || txtInputTemp.charAt(track - 1) == "u" || txtInputTemp.charAt(track - 1) == "v" || txtInputTemp.charAt(track - 1) == "w" || txtInputTemp.charAt(track - 1) == "x" || txtInputTemp.charAt(track - 1) == "y" || txtInputTemp.charAt(track - 1) == "z" || txtInputTemp.charAt(track - 1) == "." || txtInputTemp.charAt(track - 1) == "'" || txtInputTemp.charAt(track - 1) == "-" || txtInputTemp.charAt(track - 1) == " ") { }
Any help is appreciated.
It can rewrite a-z to range specification.
somechar>="a" && somechar<="z"
But I have no idea how to shorten these symbols.
== "."
== "'"
== "-"
== " "
var somechar:String = txtInputTemp.charAt(track - 1);
if ((somechar>="a" && somechar<="z")||somechar == "."||somechar == "'"||somechar == "-"||somechar == " ")
{
// do something
}
Working Example: http://wonderfl.net/c/A9Hv
Option2: Use array.indexOf(char) == -1 or not.
var someArray: Array = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",".","'","-"," "];
var somechar:String = txtInputTemp.charAt(track - 1);
if (someArray.indexOf(somechar) != -1)
{
// Do something
}

Why exactly the output of this expression return true

I have this expression:
!(1 && !(0 || 1))
The output returns 1 true. And that's ok. When I read the expression I came to the same conclusion before checking the output. But I would really appreciate if someone can explain to me why the returning value is true, that way, I will have a better understanding of boolean logic and how to implement better evaluators in my code.
Key observation here: ! is not, && is the "And" operator, and || is the "Inclusive Or" Operator.
What are you really asking when you say "why it's true?".
0 = false
1 = true
AND && table
0 0 -> 0
0 1 -> 0
1 0 -> 0
1 1 -> 1
OR || table
0 0 -> 0
0 1 -> 1
1 0 -> 1
1 1 -> 1
NOT ! table
0 -> 1
1 -> 0
With parentheses implying "do this first", the statement reduces using the tables above:
!(1 && !(0 || 1))
!(1 && !1)
!(1 && 0)
!0
1
But I don't know "why" it's true. Because that's what an AND operation is, what an OR operation is, and what a NOT operation is, and how reducing a statement works. With those definitions, it can't be another answer, so it's that answer. But you already know that, because you did it yourself and got the same answer ... so what does the question mean?
The innermost expression (0 || 1) is always true.
So !(0 || 1) is always false.
That leaves 1 && 0, which is always false.
So !(false) is always true.
Please forgive my freely intermixing 0/false and 1/true.
The human evaluator (:-).
Working through the expression, following order of operation:
!(1 && !(0 || 1))
= !(1 && !(1))
= !(1 && 0)
= !(0)
= 1
Step by step explanation:
1 = true
0 = false
Starting point: !(1 && !(0 || 1))
Lets start with the inner most expression: !(0 || 1)
Var1 || Var2 =
Var1 or Var2 =
If Var1 or Var2 is 1 or both are 1, the result is 1.
(0 || 1) = 0 or 1 -> the second variable is 1 so the expression is 1.
Insert the result (0 || 1) = 1 into Startingpoint: !(1 && !(1))
! = not (inverts the value of what is behinde)
!1 = 0
!0 = 1
!(0 || 1) = !(1) = 0
Insert the result !(1) = 0 into Startingpoint: !(1 && 0)
So we have !(1 && 0)
Var1 && Var2 = And =
the opossite of or =
If Var1 AND Var2 are both 1, the result is 1. Else it is 0 =
If Var1 or Var2 is 0, the result is zero
1 && 1 = 1
1 && 0 = 0
everything else: 0
So this is left: !(0)
Reminder: ! = not = inverts the expression behind it. So !0 = 1 (and !1 = 0)
This is 1. Or in your case: true
A good book for Beginner C programmers and people who want to learn about programming and logic in an easy, understandable way:
C for Dummies by Dan Godkins
!(1 && !(0 || 1))
Since, you have used parenthesis, evaluation takes place according to them.
First, evaluate innermost parenthesis.
0 || 1 => always true.
!(0 || 1) => !(true) => always false.
1 && !(0 || 1) => 1 && false => always false.
!(1 && !(0 || 1)) => !false => always true.

Why does the second condition fail to execute correctly?

I have the following expression in a Derived Column transformation.
((DT_STR,1,1252)outGender == "M" || (DT_I1)outGender == 1) ? 1 : (((DT_STR,1,1252)outGender == "F" || (DT_I1)outGender == 2) ? 2 : 3
When I run the package, if the "outGender" column contains a "1" or "M", the GenderId column becomes 1. If "outGender" is "2", the GenderId column is "2". So far, this is correct. If, however, "outGender" contains "F" then GenderId will be NULL. This is wrong.
Why does this happen and how do I fix it? If I switch the condition strings, placing the "F" conditions in the first part of the expression and "M" conditions in the second part, then NULL appears in the GenderId column for rows when the "outGender" column contains "M" values.
So this transform works fine without casting your values as integers:
((DT_STR,1,1252)outgender == "M" || (DT_STR,1,1252)outgender == "1") ? 1 : (((DT_STR,1,1252)outgender == "F" || (DT_STR,1,1252)outgender == "2") ? 2 : 3)
And if outGender is already a DT_STR type you can simplify it and just use
(outgender == "M" || outgender == "1") ? 1 : ((outgender == "F" || outgender == "2") ? 2 : 3)

Counting Date Columns in Rails

I'm getting stuck on how to count a date. I have 3 different columns:
demodate1, demodate2, demodate3
If demodate1 exists I want to count it as 1, if demodate 2 exists, I want to count it as 1, if demodate3 exists I want to count it as 1. If more than 1 of those exist I want to add them all together.
How can I do this?
Here's my try at the code:
def demosheld
if demodate1.present? or demodate2.present? or demodate3.present?
demodate1.count + demodate2.count + demodate3.count
end
end
def demosheld
count = 0
count = count + (demodate1.present? ? 1 : 0)
count = count + (demodate2.present? ? 1 : 0)
count = count + (demodate3.present? ? 1 : 0)
end
Edit:
Other options are
[demodate1, demodate2, demodate3].inject{|sum,date| sum + date.present? ? 1 : 0 }
sum = 0
[demodate1, demodate2, demodate3].each { |date| sum += date.present? ? 1 : 0 }
How about some inject magic?
def demosheld
[demodate1, demodate2, demodate3].inject(0) do |sum, date|
sum + (date.present? ? 1 : 0)
end
end

Using Max in LINQ to SQL

Trouble with using Max in where clause of LINQ to SQL. Data below:
QID, Question, TypeID, Disable, VersionID, Sequence
1 Who's on 1st 1 False 1 1
2 Who's on 1st 1 False 2 1
3 What's on 2nd 1 False 1 2
4 What's on 2nd 1 False 2 2
5 I don't know 1 False 1 3
6 I don't know 1 False 2 3
I need to return a group of questions based on the Max of the VersionID as noted below. The result I expect from the data above would include rows 2, 4 & 6 ordered by Sequence.
IEnumerable<QUESTION> questions =
(from q in dataContext.QUESTIONs
where q.TypeID == Convert.ToInt16(ddlType.SelectedValue)
&& (q.Disable == null || q.bDisable == false)
&& (q.VersionID == dataContext.QUESTIONs.Max(q.nVersionID))
orderby q.Sequence ascending
select q);
Max() translates properly in linq-to-sql
Try
IEnumerable<QUESTION> questions = (from q in dataContext.QUESTIONs
let maxVersion = dataContext.QUESTIONs.Max(q.nVersionID)
where q.TypeID == Convert.ToInt16(ddlType.SelectedValue)
&& (q.Disable == null || q.bDisable == false)
&& (q.VersionID == maxVersion)
orderby q.Sequence ascending
select q);