Decode(false,
ivar>10,'variable is greater than 10',
ivar<25, ' variable is less than 25 ',
'No match found ')
where ivar=25
What will be the answer as tha options are
..Greater than 10
..Less than 25
..No match found
..Error : expression is invalid
I think that the right answer is: variable is less than 25
because of:
Case Statements/Decode Function in Informatica
DECODE
Try to explain
First param is false - that means that we are waiting for the first false
first_search than first_result in params and last - default value that's why i check about the syntax and param numbers and it's ok. Than i'm watch on a value ivar=25
25 < 10 - true, but we need a false. 25 < 25 NO - that's what we are waiting for
If i'm mistaken tell me.
Related
In TSQL I need to create a script to remove all leading zero's between '.', starting with the first 0 in the string EXCEPT when there is a '.0.' anywhere in the middle of the task number. What I have so far does fine when the task number does not have EX: 111.0.123.234, but I cannot seem to figure out the combination of SUBSTRING/CHARINDEX/PATINDEX, etc. to remove all leading zeros except when the zero is the only number between '.' See attached screenshot and script/partial results as an example.
Here is my script:
SELECT TASKPRODUCTID, (CASE WHEN TASKPRODUCTID NOT LIKE '%.0.%' THEN
REPLACE(LTRIM(REPLACE(TASKPRODUCTID,'0','')),' ','0') ELSE
SUBSTRING(TASKPRODUCTID, PATINDEX('%[^0 ]%', TASKPRODUCTID + ' '), LEN(TASKPRODUCTID))
END) AS NewTaskProductID
FROM TASK
Here is a partial resultset:
TASKPRODUCTID NewTaskProductID
003.007.002.001 3.7.2.1
003.007.002.003 3.7.2.3
004.003.003.008.0.2017275.132925 4.003.003.008.0.2017275.132925
004.005.001.003 4.5.1.3
004.005.004.004.0.2017275.135139 4.005.004.004.0.2017275.135139
004.005.007.005.0.2017275.140304 4.005.007.005.0.2017275.140304
002.001.002 2.1.2
002.004 2.4
016.010 16.1
Screenshot Example of leading zero in highlighted rows still have leading zeros in next decimal section(s)
Thank you!!
You could try using the STUFF() to get the .0. in the else case scenario
declare #s AS varchar(100) = '0010.0.005.006025'
print stuff(REPLACE(LTRIM(REPLACE(#s,'0','0')),'0','*'),
patindex('%.*.%',REPLACE(LTRIM(REPLACE(#s,'0','0')),'0','*')), 3,'.-.')
OUTPUT
**1*.-.**5.**6*25
Now treat this as first scenario ; only difference is that we have got '*' instead of '0'
Hello, I am new to learning how to develop sqr programs within PeopleSoft. I've been going through some programs we are utilizing and wanted to see if someone could help provide clarification with what the below snippet of code is doing in this While loop.
if $path != ''
let $Archive_File = $path || 'ARCHIVE\' || $filename || $Curr_Date || '.dat'
open $Out_File as 1 for-reading record=450:vary status=#fileread
open $Archive_File as 2 for-writing record=450:vary status=#filewrite
While 1
if #END-FILE
break
else
read 1 into $Current_Line:999
write 2 from $Current_Line
end-if
End-While
close 1
close 2
end-if
I'm trying to understand if the WHILE statement is evaluating the "$Out_File as 1" as the logical expression, or is 1 being evaluated as the value of the variable #END-FILE (As I understand this variable is set to either 0 or 1).
Its a true loop, it will go there until reach a BREAK.
In this case if #END-FILE is true, the loop will break.
In addition to the file name, the open command takes a number as a parameter which it uses as a handler for the file. In your example, two files are being opened.
The WHILE 1 statement doesn't have anything to do with file 1. Here 1 means true, instead of 0 for false. So 1 is always true, creating an endless loop unless something within the loop breaks out if it, which in this case is the BREAK command.
The #END-FILE variable contains FALSE when the file cursor is not at EOF, and a TRUE when the the file cursor is at EOF.
An alternative, which uses less lines of code and is easier to understand might look like this:
if $path != ''
let $Archive_File = $path || 'ARCHIVE\' || $filename || $Curr_Date || '.dat'
open $Out_File as 1 for-reading record=450:vary status=#fileread
open $Archive_File as 2 for-writing record=450:vary status=#filewrite
While Not #END-FILE
read 1 into $Current_Line:999
write 2 from $Current_Line
End-While
close 1
close 2
end-if
I would like to define a datetime type variable that is a result of a simple arithmetic operation between datetime type variables.
I've defined:
datetime duration = ( TimeCurrent() - OrderOpenTime() );
datetime TmStop = StringToTime( "1970.01.01 16:00" );
but when I call it in some other arithmetic operation or generally in code like this
ExitBuy_H1 = ( duration > TmClose && ...
or this
text[3]= "Duration: " + TimeToStr( duration, TIME_MINUTES );
it doesn't work.
TmStop instead works fine.
Does anyone know why?
datetime is a simple integer, number of seconds passed since 1970.01.01 00:00. duration in your example is also in seconds, even though it is datetime formated, when you need it in minutes, divide by 60. TmClose from your example means 16*60*60 seconds and you can compare that integer with any other int of course, but what might be the reason for that?
if you hold you position more then 16 hours, then duration > TmClose is true. if you want to convert difference in seconds (duration) into time, then you will have time converted from 1970.01.01 00:00 + duration seconds.
Anyway it is not clear what is your goal in doing this calculations? if you want to make sure that you hold that particular position more then x hours, then simple bool holdMoreThanXHours = TimeCurrent()-OrderOpenTime()>x*PeriodSeconds(PERIOD_H1), and do not forget to reselect each ticket if you have several ones in open
Fact A) the code, as-is, absolutely out of any question works.
//+------------------------------------------------------------------+
//| Test_StackOverflow.mq4 |
//+------------------------------------------------------------------+
#property strict
void OnStart() {
datetime duration = ( TimeCurrent() - OrderOpenTime() );
string txt = "Duration: " + TimeToStr( duration, TIME_MINUTES );
}
//+------------------------------------------------------------------+
0 error(s), 0 warning(s), compile time: 2000 msec 1 1
Fact B) the full MCVE-context of the code, as-is, is missing.
StackOverflow requires users to post a complete MCVE-representation of the problem. This requirement was not met in the original post.
While the datetime and int data-types are mutually interchangeable, the problem does not seem to be hidden in this intrinsic "duality" of a value representation, but must be somewhere else.
The main suspects for Why? are:
variable definition was masked by another variable having the same name
variable scope-of-definition was exceeded ( asking a variable outside of it's scope )
db.Pool-operations were not preceded by OrderSelect()
I am learning from the project angular2-rxjs-chat application ong github. In the code here there is a line of code given below:
threads[message.thread.id] = threads[message.thread.id] ||
message.thread;
where threads has earlier been defined on line 29 in the code as shown below:
let threads: {[key: string]: Thread} = {};
The comments in the code states that "store the message's thread in our acuuculator 'threads'. I need a little bit explanation of how does the assignment works on line 31 as on both sides of the assignment operator we have the same thing i.e., threads[message.thread.id]. If the statement on line 31 was like
(threads[message.thread.id] = message.thread;)
then I would explain it as a value is being assigned to a key in the map "threads". But I don't understand the full line.
This means if threads[message.thread.id] already has a value then keep it, otherwise set the value to meassage.thread.
If the part before || evaluates to a value that is truthy (not null, undefined, false, ...)then the part after||is not evaluated and the result from the part before||is returned otherwise the result from the expression after||` is returned.
You could also write it as
if(!threads[message.thread.id]) {
threads[message.thread.id] = message.thread;
}
I'm building a Rails 4 API with JSON, and am returning the updated_at attribute as UTC timezone in ISO format.
record.updated_at # => 2015-04-14 10:01:37 -0400
record.updated_at.utc.iso8601 # => "2015-04-14T14:01:37Z"
However, my rspec specs will occasionally fail intermittently when the updated_at is off by 1 second:
# records_controller_spec.rb
RSpec.describe RecordsController do
describe "update - PUT #update" do
record = FactoryGirl::create(:record, value: "original")
record_params = { value: "updated" }
xhr :put, api_v1_record_path(record), record_params
# Uses ActiveModelSerializer
# json = JSON.parse(response.body)
expect(response).to have_http_status(:ok)
expect(json["updated_at"]).to eq(record.updated_at.utc.iso8601)
end
end
# app/serializers/record_serializer.rb
class RecordSerializer < ActiveModel::Serializer
attributes :id, :created_at, :updated_at, :value
def created_at
object.created_at.utc.iso8601
end
def updated_at
object.updated_at.utc.iso8601
end
end
# Running rspec...
Failure/Error: expect(json["updated_at"]).to eq(record.updated_at.utc.iso8601)
expected: "2015-04-14T13:59:35Z"
got: "2015-04-14T13:59:34Z"
(compared using ==)
If I run the spec again, it passes many times, and then randomly it will fail again, with the time comparison being off by 1 second again.
Is there anyway to ensure consistent datetime conversions in the specs?
The biggest issue is that automated deploys with a CI server will randomly fail if the rspec suite randomly fails if a spec just happens to be on the fence of a given second.
The solution was I wasn't reloading the object after the update actions, thus I was getting a "dirty" updated_at, and it failed sporadically because the tests happened so fast.
RSpec.describe RecordsController do
describe "update - PUT #update" do
record = FactoryGirl::create(:record, value: "original")
record_params = { value: "updated" }
# record.updated_at => "2015-06-23 22:30:00"
xhr :put, api_v1_record_path(record), record_params
# record.updated_at => "2015-06-23 22:30:00"
# SOLUTION CODE (notice timestamp updated below)
record.reload
# record.updated_at => "2015-06-23 22:30:01"
# Uses ActiveModelSerializer
# json = JSON.parse(response.body)
expect(response).to have_http_status(:ok)
expect(json["updated_at"]).to eq(record.updated_at.utc.iso8601)
end
end
I found that for any of my specs that altered/updated a record, I would have to reload the object to get the proper timestamps values. I don't have better general approach than that.
If someone has a cleaner solution, feel free to post it and I'll accept it over mine.