November 26, 2011 at 8:09 am
I would be doing this in SSRS, and starting with seconds, as an integer. Thank you so much for your help!
November 26, 2011 at 8:49 am
I'll have to leave it to one of the others, thenm Robin. SSRS isn't my strong suite.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 26, 2011 at 12:09 pm
After much rummaging, I've found the answer here: http://www.sqlservercentral.com/articles/Reporting+Services+(SSRS)/67660/
Here's the function for the report: =Code.GetDurationAsString(<fieldname>)
Here's the code:
Function GetDurationAsString(ByVal total As Double) As String
Dim hour As Integer
hour = Math.Floor(total / 3600)
Dim min As Integer
min = Math.Floor((total - (hour * 3600)) / 60)
Dim sec As Integer
sec = Math.Floor(total - (hour * 3600) - (min * 60))
Dim retThis As String
If hour > 999 Then
retThis = Microsoft.VisualBasic.Right("0000" + RTrim(CType(hour, String)), 4) & ":" & Microsoft.VisualBasic.Right("00" & RTrim(CType(min, String)), 2) & ":" & Microsoft.VisualBasic.Right("00" & RTrim(CType(sec, String)), 2)
ElseIf hour > 99 Then
retThis = Microsoft.VisualBasic.Right("000" + RTrim(CType(hour, String)), 3) & ":" & Microsoft.VisualBasic.Right("00" + RTrim(CType(min, String)), 2) & ":" & Microsoft.VisualBasic.Right("00" & RTrim(CType(sec, String)), 2)
Else
retThis = Microsoft.VisualBasic.Right("00" + RTrim(CType(hour, String)), 2) & ":" & Microsoft.VisualBasic.Right("00" + RTrim(CType(min, String)), 2) & ":" & Microsoft.VisualBasic.Right("00" & RTrim(CType(sec, String)), 2)
End If
Return retThis
End Function
Thank you Frank Fernando!!
November 27, 2011 at 12:43 pm
I guess that might be yet another reason for me to dislike SSIS. It's a whole lot simpler in T-SQL.
SELECT CONVERT(VARCHAR(10),DATEDIFF(hh,0,DATEADD(ss,SecondsColumn,0)))
+ RIGHT(CONVERT(CHAR(8),DATEADD(ss,SecondsColumn,0),108),6)
--Jeff Moden
Change is inevitable... Change for the better is not.
November 27, 2011 at 8:27 pm
@robin - A very small change to my original post gives you what you want with significantly less code required. I've pasted it below.
Personally, I'd still be tempted to use TSQL (ie have 2 columns, one that has the seconds and the other with the formated value) but, if you're insisting on doing it in SSRS, try the following.
In the Code section of the Report (go to Report Properties), add the code below
Function secondsToString(seconds As Int64) As String
Dim myTS As New TimeSpan(seconds * 10000000)
Return String.Format("{0:00}:{1:00}:{2:00}:{3:00}", myTS.Days, myTS.Hours, myTS.Minutes, myTS.Seconds)
End Function
Then in your report item Textbox, edit the Expression and add
= Code.secondsToString(Fields!seconds.Value) keeping in mind that your field *will not* be called 'seconds', so change it appropriately.
This should return you a formated string of 00:00:19:08 (ie 0 days 0 hours, 19 minutes and 8 seconds) for the value 1148.
@jeff - i think you meant SSRS not SSIS, but heck, there's reasons to not like either on any given day :):hehe:
Steve.
November 27, 2011 at 8:34 pm
Removed post.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
November 28, 2011 at 11:52 am
Steve,
You're right, that is much shorter and more concise, thank you!! This will come in really handy for this company as they build contact center software, so much of what is reported on is time. Super-handy!!
Thanks again,
Robin
November 28, 2011 at 9:40 pm
stevefromOZ (11/27/2011)
@jeff - i think you meant SSRS not SSIS, but heck, there's reasons to not like either on any given day :):hehe:
They're all 4 letter words to me. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
November 28, 2011 at 9:52 pm
After the day I've had with SSIS today, i'm with you on that one!
Steve.
Viewing 9 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply