SSRS Format seconds as time (negative seconds) - reporting-services

I have a column with integers: TotalSec that has seconds. It can be 0, negative or positive.
I have to format these seconds in a report. But cant get something working for the negative seconds.
My logic:
For 0 = Nothing,
For Positive format as HH:mm:ss
For Negative - ABS the value then format as -HH:mm:ss
=IIF(SUM(Fields!TotalSec.Value)=0, Nothing, IiF(SUM(Fields!TotalSec.Value)>0,
Format(DateAdd("s",SUM(Fields!TotalSec.Value), "00:00:00"), "HH:mm:ss"), "-" & Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I get an #Error for the Negative numbers. With the warning:
Warning 2 [rsRuntimeErrorInExpression] The Value expression for the textrun ‘TotalSec.Paragraphs[0].TextRuns[0]’ contains an error: The added or subtracted value results in an un-representable DateTime. Parameter name: value

It worked like this:
=IIF(SUM(Fields!TotalSec.Value)=0,Nothing,IIF(SUM(Fields!TotalSec.Value)< 0,"-"&Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss"),Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))

I cleaned up the previous answer:
=IIf(Fields!elapsed.Value < 0, "-", "+")
&
Format(
DateAdd(
"s",
Abs(Fields!elapsed.Value),
"00:00:00"
),
"HH:mm:ss" ' can be m:ss
)
The "+" is to keep the results lined up, and can be replaced with "" if desired.

Related

DateDiff with DateTime in SSRS expression

I am trying to calculate the time difference between two DateTime parameters in a SSRS expression to display in DD:hh:mm:ss format. With the expression I am using I am getting:
Start: 03/04/2016 08:48:53 AM End: 03/07/2016 11:24:04 AM Elapsed: 74:33:11.
I would like to see Elapsed: 3:02:35:11 (days:hours:minutes:seconds).
Divide the hours by 24 to get Days, and then do a Modulo to get the remaining hours.
Try this:
=Floor(
DateDiff("s",Fields!ProcessOpened.Value,Fields!ProcessClosed.Value)
/ 86400) & ":" & Format(DateAdd("s",
DateDiff("s",Fields!ProcessOpened.Value,
Fields!ProcessClosed.Value), "00:00:00"), "HH:mm:ss")
I've tested with:
=Floor(DateDiff("s",CDATE("04/03/2016 08:48:53 AM"),
CDATE("07/03/2016 11:24:04 AM")) / 86400) & ":" &
Format(DateAdd("s", DateDiff("s",CDATE("04/03/2016 08:48:53 AM"),
CDATE("07/03/2016 11:24:04 AM")), "00:00:00"), "HH:mm:ss")
It returns:
3:02:35:11
Let me know if this helps.

Using Expressions in SSIS Casting Issue

I'm using expressions in the Control Flow to choose different Data Flow Tasks based upon the name o file being parsed (basically loading data from Excel Source into OLE DB Destination).
I'm using the following Expression and its variants to get the desired result:
(DT_I4) (DT_WSTR, 2) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
(DT_BOOL) (DT_WSTR, 2) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
(DT_BOOL) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
I basically just want the DFT to be executed only if the expression is true. There are some casting errors coming.
The most promising result comes when I use this expression:
(DT_WSTR, 2) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
Where the answer is basically '45' in string form so I cannot use any logical operators or compare them against any numbers ...
Any help would be much appreciated.
Why not just compare the FINDSTRING result against 0 (not found)?
FINDSTRING("DIVISION_ABC.xls", "DIVISION", 1 ) > 0
That would evaluate to True - just replace "DIVISION_ABC.xls" with #[User::srcFilePath]

Can I use leading zero in case of day in the Date field in SMTP

Can I use leading zero in case of day in the Date field in SMTP?
I mean smth like
03 Apr 2014 13:10:22 +0000
Can you quote RFC, please?
There are no dates in the SMTP protocol, but you are probably referring to email header fields as described by RFC 2822 Internet Message Format. From http://www.ietf.org/rfc/rfc2822.txt we have section 3.3 Date and Time specification, with the following selected fields:
date-time = [ day-of-week "," ] date FWS time [CFWS]
day-of-week = ([FWS] day-name) / obs-day-of-week
day-name = "Mon" / "Tue" / "Wed" / "Thu" /
"Fri" / "Sat" / "Sun"
date = day month year
year = 4*DIGIT / obs-year
month = (FWS month-name FWS) / obs-month
month-name = "Jan" / "Feb" / "Mar" / "Apr" /
"May" / "Jun" / "Jul" / "Aug" /
"Sep" / "Oct" / "Nov" / "Dec"
day = ([FWS] 1*2DIGIT) / obs-day
...
which states that the day part of the date should be between 1-2 digits, and this does not specifically prohibit using a leading zero. Nothing seems to be said about the optional leading zero, so proper interpretation should always allow it while parsing.
The obs- alternative variants describe old obsolete formats, e.g. 2-digit years and comments or folding white-space between any part.

IIF Statements with blank or alpha characters in MS Visual Basic

I have a field CODE_USER_2 that can be equal to 1.75, 2, 2.62, 3.75, 5.25, 6, OT(w/2 spaces, or __(4 spaces). If it is 1.75, 2, 2.62, 3.75, 5.25, 6 I would like corresponding weights to result (THIS PART WORKS).
If the field is __ or OT, I would like the equation to result with 0. I currently get #error with the following formula.
=IIf(Fields!CODE_USER_2_IM.Value= " " OR "OT " ,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895))
Please let me know if you have ideas!
You have to repeat "Fields!CODE_USER_2_IM.Value = " after the OR.
Or try this - less wordy but more obscure :
=IIf( ( " |OT |" ).Contains(Fields!CODE_USER_2_IM.Value + "|"
,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895
, True , 0))
Always close out a Switch with:
, True , [default value] )
Also beware that matching in SSRS expressions is exact e.g. 2 spaces not = 4 spaces.

quadratic equation

Question: I have a program that solves a quadratic equation. The program gives real solutions only. How do I perform the quality testing of the program? Do you need to ask me for some extra input parameters?
Create test cases, and check the result of your program against the expected result (which is calculated externally) in the test case.
The test cases can cover several ordinary cases, together with special cases, such as when the coefficient is 0, or the discriminant is < 0, = 0, near 0. When you compare the result, make sure you handle the comparison properly (since the result is floating point numbers).
# "quadratic-rb.rb" Code by RRB, dated April 2014. email ab_z#yahoo.com
class Quadratic
def input
print "Enter the value of a: "
$a = gets.to_f
print "Enter the value of b: "
$b = gets.to_f
print "Enter the value of c: "
$c = gets.to_f
end
def announcement #Method to display Equation
puts "The formula is " + $a.to_s + "x^2 + " + $b.to_s + "x + " + $c.to_s + "=0"
end
def result #Method to solve the equation and display answer
if ($b**2-4*$a*$c)>0
x1=(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a))
x2=(-(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a)))
puts "The values of x1 and x2 are " +x1.to_s + " and " + x2.to_s
else
puts "x1 and x2 are imaginary numbers"
end
end
Quadratic_solver = Quadratic.new
Quadratic_solver.input
Quadratic_solver.announcement
Quadratic_solver.result
end