SSIS Derived column Transformation setting to BOOL with UPPER(LTRIM(RTRIM - ssis

I have a Flag which needs to be set to 1 or 0. so i used Derived column transformation to convert it to bool
as you can se the code it works only when i use an OR operator for both Y and N .
This code below works for IF Flag is Y and N condition
(DT_BOOL)(Flag == "Y" ? 1 : 0) || (DT_BOOL)(Flag == "N" ? 0 : 1)
** working only when FLAG = (Capital)Y OR N *****************
but if my Flag is small 'n' it does not work it still sets to TRUE
I want to make it UPPER and TRIM it at the same time . Which i am having hard time to figure out .
This is my code but it does not work
(DT_BOOL)(UPPER(RTRIM(LTRIM
(Flag == "Y" ? 1 : 0)
)))
||(DT_BOOL)(UPPER(RTRIM(LTRIM(Flag == "N" ? 0 :1)
))) ***** this code is not working *****************
Thanks for your time.
PLEASE look at Tranformation Pic

Try this...
(DT_BOOL)(UPPER(RTRIM(LTRIM(Flag))) == "N" ? 0 :1)

Related

Substring question on mips assembly language

Please help as soon as possible...
Write a MIPS assembly language program that prompts the user to input two strings (each should be no longer than 50 characters including the null terminator). Your program should determine whether the second string is a substring of the first. If it is, then your program should print out the first index in which the second string appears in the first. For example, if the first string is “Hello World” and the second string is “lo”, then the program should print out 3, i.e. the starting index of “lo” in “Hello World.” If the second string is not contained in the first string, then your program should print out -1.
To be able to understand what you have to implement at assembly level, the first thing you should do, is understanding the high-level algorithm. Why?
It's easier for you to see all the cases and edge-cases in time!
To look back at what have I been trying to do again? in the middle of programming the Assembly version.
To quickly see which variables you (certainly) need.
I wrote following program (forgive me, python has been a while for me):
def is_in_string_1(string, substring):
"""
aaba: a, b, ab, ba, aba (last one will fail)
"""
length = len(string)
sublength = len(substring)
if (sublength == 0):
return True
j = 0
for i in range(0, length):
if string[i] != substring[j]:
j = 0
else:
j += 1
if j == sublength:
return True
return False
def is_in_string_2(string, substring):
"""
aaba: a, b, ab, ba, aba
"""
length = len(string)
sublength = len(substring)
for i in range(0, length + 1 - sublength): # string: aabc; substring: c; length: 4; sublength: 1; indexes: 0,1,2,3;
is_substring = True
for j in range(0, sublength): # for the sake of the algorithm, no slicing here
if string[i+j] != substring[j]:
is_substring = False
break
if is_substring:
return True
return False
stringTuples = [
("aaa", "aa"),
("aaa", "aaa"),
("aaa", "aab"),
("abc", "bc"),
("abc", "a"),
("abc", "abc"),
("aaa", ""),
("aaa", "b")
]
for stringTuple in stringTuples:
print(
stringTuple[0],
stringTuple[1],
':',
is_in_string_1(stringTuple[0], stringTuple[1]),
is_in_string_2(stringTuple[0], stringTuple[1]),
sep='\t'
)
I first thought I could optimize the standard solution (is_in_string_2), leaving out the second for-loop (is_in_string_1), but after some thinking I already found out it would fail (the edge-case wasn't even in any of my test-data!) - so I left it as an example for how important it is that you use a correct algorithm.
The program produces the following output:
aaa aa : True True
aaa aaa : True True
aaa aab : False False
abc bc : True True
abc a : True True
abc abc : True True
aaa : True True
aaa b : False False
aaba aba : False True
Notice how all output was correct, except for the last line, where the first algorithm is wrong.
Before you continue:
You have to make your own len() function in MIPS; note that all string are (if I remember correctly) null terminated, so you'll have to count all non-null characters of a string, or in other words, count how many characters precede the null-terminator.
You should use j, $ra and jr calls to go to a "function" or subroutines. (Search)
While in one, you can call other functions using the stack. (Search)

Getting warning message

I am trying to run this code:
x = 0
y = 0
newdata <- subset(data, subject_ids == 25773861)
for(i in newdata$classification_id){
if(newdata$value == "Yes"){
x = x + 1
} else {
y = y + 1
}
}
But keep getting this warning:
Warning messages:
1: In if (newdata$value_simple == 0) { :
the condition has length > 1 and only the first element will be used
2: In if (newdata$value_simple == 0) { :
the condition has length > 1 and only the first element will be used
Any advice or help in solving this?
The general code of
if(condition){
some code
}else{
some code}
only look at the first value in the vector. So it is basically warning you that it is only looking at the first value in the object newdata$value. I am assuming you are getting all in either x or y not a split like you would want.
The two things I would fix in that code, start at the first two lines of the for loop
x = 0
y = 0
newdata <- subset(data, subject_ids == 25773861)
for(i in seq_along(newdata$classification_id)){ #seq_along makes a vector 1 to the length of your vector
if(newdata$value[[i]] == "Yes"){ #This will subset the newdata$Value into single values
x = x + 1
} else {
y = y + 1
}
}
Another option is to use the tidyverse, assuming you have it installed
library(tidyverse)
data %>%
filter(subject_ids == 25773861) %>%
group_by(value) %>%
count()

Nested ternaries, can't spot the error

I have this nested ternary expression in SSIS that I can't seem to get to work, my eyes are about to come out of my skull.
FINDSTRING(TRIM(f3),"BASICS",1) != 0 ? (UPPER(LEFT(TRIM(f3),1)) == "F" ? #[User::FallBasicsEntityId] : (UPPER(LEFT(TRIM(f3),1)) == "S" ? #[User::SpringBasicsEntityId] : #[user::BasicsEntityId])) : (UPPER(LEFT(TRIM(f3),1)) == "F" ? #[user::FallEntityId] : (UPPER(LEFT(TRIM(f3),1)) == "S" ? #[user::SpringEntityId] : #[user::DefaultEntityId]))
Here's an "indented" version:
FINDSTRING(TRIM(f3),"BASICS",1) != 0
? (
UPPER(LEFT(TRIM(f3),1)) == "F"
? #[User::FallBasicsEntityId]
: (
UPPER(LEFT(TRIM(f3),1)) == "S"
? #[User::SpringBasicsEntityId]
: #[user::BasicsEntityId]
)
)
: (
UPPER(LEFT(TRIM(f3),1)) == "F"
? #[user::FallEntityId]
: (
UPPER(LEFT(TRIM(f3),1)) == "S"
? #[user::SpringEntityId]
: #[user::DefaultEntityId]
)
)
What am I missing? It looks to me like the parentheses are balanced and properly placed.. or are they?
I'm about to ditch this and resort to a script component... it seems to me such an expression would be easier to maintain with C# code...
The parentheses are balanced; the problem is that user is not the same as User.

ruby xml parsing: `dup': can't dup NilClass (TypeError)

I am parsing xml recods using ruby. XML file has following data strcuture:
<row Id="27" PostTypeId="2" ParentId="11" CreationDate="2008-08-01T12:17:19.357" Score="13" Body="<p>#jeff</p>
<p>IMHO yours seems a little long. However it does seem a lit
tle more robust with support for "yesterday" and "years". But in my experience when this is used the person is most likely to view the content in the first 30 days. It is only the really har
dcore people that come after that. So that is why I usually elect to keep this short and simple.</p>
<p>This is the method I am currently using on one of my websites. This only re
turns a relative day, hour, time. And then the user has to slap on "ago" in the output.</p>
<pre><code>public static string ToLongString(this TimeSpan time)<br&g
t;{<br> string output = String.Empty;<br><br> if (time.Days &gt; 0)<br> output += time.Days + " days ";<br><br> if ((time.Days == 0 || time.Days =
= 1) &amp;&amp; time.Hours &gt; 0)<br> output += time.Hours + " hr ";<br><br> if (time.Days == 0 &amp;&amp; time.Minutes &gt; 0)<br> outp
ut += time.Minutes + " min ";<br><br> if (output.Length == 0)<br> output += time.Seconds + " sec";<br><br> return output.Trim();<br>}<br>
</code></pre>" OwnerUserId="17" LastEditorUserId="17" LastEditorDisplayName="Nick Berardi" LastEditDate="2008-08-01T13:16:49.127" LastActivityDate="2008-08-01T13:16:49.127" CommentCount="1" CommunityO
wnedDate="2009-09-04T13:15:59.820" />
But there are some records that doesn't have all the elements
<row Id="29" PostTypeId="2" ParentId="13" CreationDate="2008-08-01T12:19:17.417" Score="18" Body="<p>There are no HTTP headers that will report the clients timezone so far although it has been suggested t
o include it in the HTTP specification.</p>
<p>If it was me, I would probably try to fetch the timezone using clientside JavaScript and then submit it to the server using Ajax or so
mething.</p>" OwnerUserId="19" LastActivityDate="2008-08-01T12:19:17.417" CommentCount="0" />
My ruby parse goes through these XML records and insert them into an MySQL database:
def on_start_element(element, attributes)
if element == 'row'
#post_st.execute(attributes['Id'], attributes['PostTypeId'], attributes['AcceptedAnswerId'], attributes['ParentId'], attributes['Score'], attributes['ViewCount'],
attributes['Body'], attributes['OwnerUserId'] == nil ? -1 : attributes['OwnerUserId'], attributes['LastEditorUserId'], attributes['LastEditorDisplayName'],
DateTime.parse(attributes['LastEditDate']).to_time.strftime("%F %T"), DateTime.parse(attributes['LastActivityDate']).to_time.strftime("%F %T"), attributes['Title'] == nil ? '' : attributes['Title'],
attributes['AnswerCount'] == nil ? 0 : attributes['AnswerCount'], attributes['CommentCount'] == nil ? 0 : attributes['CommentCount'],
attributes['FavoriteCount'] == nil ? 0 : attributes['FavoriteCount'], DateTime.parse(attributes['CreationDate']).to_time.strftime("%F %T"))
post_id = attributes['Id']
tags = attributes['Tags'] == nil ? '' : attributes['Tags']
tags.scan(/<(.*?)>/).each do |tag_name|
tag_id = insert_or_find_tag(tag_name[0])
#post_ot_tag_insert_st.execute(post_id, tag_id)
end
end
end
But during the processing of second record based on whats been insert in my database (Last record is the record with rows id=27) I am getting following error:
/format.rb:1031:in `dup': can't dup NilClass (TypeError)
I was wondering if its related to missing elements, lets say if its missing some elements that I am expecting in in the database I wonder how I should be handling this or set to a some kind of a default value. Such as if its a missing date set the date to some default date value.
This is the line that is getting complain:
DateTime.parse(attributes['LastEditDate']).to_time.strftime("%F %T"), DateTime.parse(attributes['LastActivityDate']).to_time.strftime("%F %T"), attributes['Title'] == nil ? '' : attributes['Title'],
I think its complaining on the LastEditDate?

Manually output HAML start and end tags

I have some code:
- count = 0
- #clients.each do |client|
%div{:class => "grid_2#{(" alpha" if (count % 3) == 0) || (" omega push_2" if (count % 3) == 2) || " push_1"}"}= link_to h(client.name), client
- count += 1
I want to output an opening div tag right after the each statement if the (count % 3) == 0 and out put the end tag at the end of the block if the (count % 3) == 2 but I can't figure out how to get HAML to do this. Any ideas?
This is a nice solution that was posted here a few weeks ago. It's not in Haml, but the idea is the same.
Rails each loop insert tag every 6 items?