SSRS change minute into day, hour and min - reporting-services

I have a Time column in which is in minute , in ssrs i need to get average and output in such a way that its in Day, Hour and min.
For example Column name is Time (Min).How to write an expression in such a way that we can get result in day, hour and min

Assuming that your time column is just an integer datatype containing a number of minutes then something like this will work.
The following calculates based on a report parameter to make it easier to test so oyu will need to swap this out for the correct column name and aggregations. e.g. if you time column is called MyTime and you want to calculate based on the average then swap out Parameters!MyMins.Value with AVG(Fields!MyTime.Value)
= INT(Parameters!MyMins.Value / 1440) & " days " &
INT((Parameters!MyMins.Value MOD 1440) / 60) & " hours " &
(Parameters!MyMins.Value MOD 60) & " mins"
adjust the output to suit you formatting requirements....
The above turns 4455 minutes into the string "3 days 2 hours 15 mins"

Enter the following expression:
=Format(TimeSerial(0,Parameters!MyMins.Value,0),"dd") & " Days "
& Format(TimeSerial(0,Parameters!MyMins.Value,0),"HH") & " Hours "
& Format(TimeSerial(0,Parameters!MyMins.Value,0),"mm") & " Minutes "
Alternatively, create another parameter e.g. MyTime
=TimeSerial(0,Parameters!MyMins.Value,0)
(Ensure that this parameter is evaluated after MyMins by moving it down the list)
Then put that into the code above
=Format(Parameters!MyTime.Value,"dd") & " Days "
& Format(Parameters!MyTime.Value,"HH") & " Hours "
& Format(Parameters!MyTime.Value,"mm") & " Minutes "

Related

SSRS format minutes as Days:Hours:Minutes

I have Arrival Date and Departure Dates and the difference between them in minutes. I would like to format the difference between the dates as DD:HH:mm (Days:24-hours format:minutes). For instance, the minutes 3245 should be shown as 02:02:45(2 days, 2 hours and 45 minutes => 21440 + 260 + 45).
I've tried DateDiff function, but could not get the exact formatting. Also I need to Sum up these at the end.
Please help me with the Report Expression.
You need to add two columns. One will display the formatted expession and one hidden will contain the datediff calculations.
Your calculation column will contain the datediff expression in minutes
= DATEDIFF("n",Fields!date1.Value,Fields!date2.Value)
For the total you can normally use SUM
= SUM(DATEDIFF("n",Fields!date1.Value,Fields!date2.Value))
Your expression display textboxes should refer to the relevant report items (in my example Textbox6 is for detail and Textbox9 is for total)
= Cstr(ReportItems!Textbox6.value \ (24*60)) & ":" &
Format( (ReportItems!Textbox6.value Mod (24*60)) \ 60, "00" ) & ":" &
Format( (ReportItems!Textbox6.value Mod (24*60)) Mod 60, "00" )
= Cstr(ReportItems!Textbox9.value \ (24*60)) & ":" &
Format( (ReportItems!Textbox9.value Mod (24*60)) \ 60, "00" ) & ":" &
Format( (ReportItems!Textbox9.value Mod (24*60)) Mod 60, "00" )

Why does SQL operation shows the same output? [duplicate]

This question already has answers here:
Compare dates in MySQL
(5 answers)
Closed last year.
when I output these two SQL operations, the columns for the two months (01 = January) and (02 = February) are summed together instead of individually. So they show the same output. But why?
If if want to output (02 February) it should not show the sum of January but it does. Where is my problem in my code?
"SELECT SUM(" + dataBaseHelper.GET_SUM + ") FROM " + dataBaseHelper.TABLE_NAME + " WHERE " + dataBaseHelper.DATE + " BETWEEN '01/01/2022' AND " + "'07/01/2022'"
and
"SELECT SUM(" + dataBaseHelper.GET_SUM + ") FROM " + dataBaseHelper.TABLE_NAME + " WHERE " + dataBaseHelper.DATE + " BETWEEN '01/02/2022' AND " + "'07/02/2022'"
The standard syntax for date in MySQL is yyyy-mm-dd. I think you could replace the dates in your where between statement using this consideration. Otherwise read string to date cast specifications.

How to get information on one line in my Expression

My expression shows just the Name, SSN, DOB and Phonenumber.
Here's my expression:
=Fields!FST_NAME.Value & vbCrLf & Fields!LAST_NAME.Value & vbCrLf & Fields!SOC_SECURITY_NUM.Value & vbCrLf & Fields!BIRTH_DT.Value & vbCrLf & Fields!ATTRIB_43.Value
I want it to show like this
Name: John Smith
Right Now it just shows John Smith
If you write one big expression your textbox will look like this:
This is hard to work with both in terms of layout and making corrections to the formula. A good alternative is to use placeholders with labels in your textbox. So you would type in "Name: " and then right click after it and select "Create Placeholder". Set the properties like this:
And the textbox can be nice to read and work with:
You can even control the formatting of the placeholders independently which comes in handy if you need to include dates or numbers.
If all of your fields are strings, then this works:
=Fields!FST_NAME.Value + " " +
Fields!LAST_NAME.Value + " " +
Fields!SOC_SECURITY_NUM.Value + " " +
Fields!BIRTH_DT.Value + " " +
Fields!ATTRIB_43.Value
However, if Birth_Dt, or any other field is not a valid string (DateTime datatype, for example) then you will need to use CStr(Fields!BIRTH_DT.Value) to convert it to a string so it can be correctly concatenated.
In an example I can do locally my expression is as follows:
=CStr(Fields!ExpMonth.Value) + " " +
Fields!ItemName.Value + " " +
Fields!ItemClass.Value
The first three rows of the result it produces look like this:
1 1 Year Membership 1 Year 1 1 Year Membership 1 Year
2 1 Year Membership 1 Year 2 1 Year Membership 1 Year
3 1 Year Membership 1 Year 3 1 Year Membership 1 Year
To add text to the string, you can encapsulate it in quotes in your concatenated string, like this:
="This is added text" + " " +
CStr(Fields!ExpMonth.Value) + " " +
Fields!ItemName.Value + " " +
Fields!ItemClass.Value
The above results now look like this:
1 1 Year Membership 1 Year This is added text 1 1 Year Membership 1 Year
2 1 Year Membership 1 Year This is added text 2 1 Year Membership 1 Year
3 1 Year Membership 1 Year This is added text 3 1 Year Membership 1 Year

SQL query to retrieve data between two dates

I've written following code:
Dim date1 As Date
Dim date2 As Date
date1 = Convert.ToDateTime(DatePickerFromDate.Text)
date2 = Convert.ToDateTime(DatePickerToDate.Text)
Dim cnd As New OleDbCommand("SELECT * FROM Sales WHERE Invoice_Date BETWEEN " + date1 + " AND " + date2 + "", om)
om.Open()
Dim da As OleDbDataReader = cnd.ExecuteReader
While da.Read()
ComboBox1.Items.Add(da(0))
End While
da.Close()
om.Close()
I want to retrieve data between two dates that are been taken from two datepickers.
I tried BETWEEN, also i tried >= =< but result was empty though database contains data. Please help where I'm getting wrong
Your code is probably generating an error. When doing this type of querying, you should store the query string after substitution and print it out. You seem to be missing delimiters around the dates. So this may work in your specific case.
New OleDbCommand("SELECT * FROM Sales WHERE Invoice_Date BETWEEN '" + date1 + "' AND '" + date2 + "'", om)
However, you then need to be careful about the format of the dates. The application layer and the database might use different formats. If you are substituting directly into the query string, then use the format YYYY-MM-DD -- it is the ISO standard date format and generally understood.
Even better is to learn how to parameterize queries so you can actually pass in the date values as date parameters.
If you're using MS Access, this should be the syntax...
SELECT * FROM Sales WHERE Invoice_Date>=#" + date1 + "# and Invoice_Date<=#" + date2 + "#"
If you're using MS SQL Server or MySQL, then do something like this...
SELECT * FROM Sales WHERE Invoice_Date>='" + date1 + "' and Invoice_Date<='" + date2 + "'"

SELECT Between dates almost working

My problem is likely all about date formatting in a SELECT.
In an asp file I open an ADO Recordset wanting to retrieve rows of a MS SQL table that fall between date1 (08/15/2013) and date2 (08/22/2013) (i.e., the previous 7 days from today's date.)
The SELECT does retrieve the appropriate 2013 rows but also retrieves rows going back to 08/15/2012.
Here is the SELECT:
oRS.Source = "SELECT * FROM aTable WHERE entry_Date BETWEEN '" & resultLowerDate & "' AND '" & resultCurrentDate & "' AND entry_Status <> 'INACTIVE'"
resultLowerDate = 08/15/2013 and resultCurrentDate = 08/22/2013.
The table is set up as follows with resultCurrentDate = "08/22/2013":
entry_Status entry_Date (varchar) LastName FirstName SELECT Result
INITIAL 08/15/2012 Smith Jim YES
INACTIVE 08/21/2012 Green Tom no
INITIAL 08/22/2013 Jones Mary yes
FOLLOWUP 08/22/2013 Jones Mary yes
FOLLOWUP 08/22/2013 Brown Sally yes
FOLLOWUP 08/22/2013 Smith Jim yes
Any thoughts as to why the INITIAL 08/15/2012 row gets selected along with the other rows that meet the SELECT query?
STOP STORING DATES IN VARCHAR COLUMNS! And STOP CONCATENATING STRINGS, USE PROPER PARAMETERS.
Sorry to yell, but we are getting multiple questions a day where people use the wrong data type for some unknown and probably silly reason, and these are the problems it leads to.
The problem here is that you are comparing strings. Try:
"... WHERE CONVERT(DATETIME, entry_date, 101)" & _
" >= CONVERT(DATETIME, '" & resultLowerDate & "', 101)" & _
" AND CONVERT(DATETIME, entry_date, 101)" & _
" < DATEADD(DAY, 1, CONVERT(DATETIME, '" & resultCurrentDate & "', 101))"
Or better yet, set resultLowerDate and resultUpperDate to YYYYMMDD format, then you can say:
"... WHERE CONVERT(DATETIME, entry_date, 101) >= '" & resultLowerDate & "'" & _
" AND CONVERT(DATETIME, entry_date, 101) < DATEADD(DAY, 1, '" & resultCurrentDate & "'"
Note that I use an open-ended range (>= and <) instead of BETWEEN, just in case some time slips into your VARCHAR column.
Also note that this query could fail because garbage got into your column. Which it can, because you chose the wrong data type. My real suggestion is to fix the table and use a DATE or DATETIME column.
The fact that your entry_Date column is a varchar field and not an actual date is the problem. If you cast it to a datetime during the select, you'll get the results you expect.
select *
from aTable
where cast(entry_Date as datetime) between '08/15/2013' and '08/22/2013'
Sql Fiddle link