Interval Based Report Sql Server - sql

I need First Login and Last Logout report for CC agents, I have information of every login and logout they perform during their shift (i.e Logout for lunch/smoke/breaktime etc).
We have the Following shifts:
S.No Shift Possible Login Possible Log Out
1. 08 – 04 8: 07 16:05
2. 10 – 06 10:03 18:09
3. 04 – 00 16:08 00:02
4. 06 – 02 18:04 02:01
5. 00 – 08 23:57 08:04
I have this view for collecting relevant information as below:
Problem with this report is that if I am generating a single day report as 20/06/2016 then I am not able to capture information on Shift S.No. (3,4,5) because there is a day change.
For Example:
Agent Login Date/Time is: 20/06/2016 18:10
And
Agent Logout Date/Time is: 21/06/2016 02:05
I need something like to have Interval column where day starts at 20/06/2016 03:00 and day ends at 21/06/2016 03:00 how to achieve this Interval ? Or if you have any other Idea for this report requirement.

If I understood you correctly, based on the view you've shown there, you need to provide data for all the people that were working on, say, 20/06/2016? If that's so, I believe you could select from the view all the people whose
CAST(FirstLogin AS date) = '20160620'
If you needed to also include the people who started working on 19/06/2016 and ended on 20/06/2016 then you would do the same for LastLogOut.
In addition, if you were to write it as a dynamic query, if you needed to provide a report for yesterday for example, you'd substitute the 20/06/2016 from the where clause with
CAST(DATEADD(day, -1, GETDATE()) AS date)

Related

Excel: Insert blank row if non consecutive date

We have a process at work that runs every 31 hours and would like to have a column in an Excel 2010 spreadsheet that reflects the time and dates the process is due to run each day over the coming year e.g.
start date (Cell:A1):
10/31/2016 1:00
11/1/2016 8:00
11/2/2016 15:00
11/3/2016 22:00
11/5/2016 5:00
11/6/2016 12:00
11/7/2016 19:00
11/9/2016 2:00
11/10/2016 9:00
11/11/2016 16:00
11/12/2016 23:00
11/14/2016 6:00
I am currently using the formula: A2 =A1 + (31/24) to populate the dates and times in the column which appears to work ok. I need to insert a blank row between days that are not consecutive (in order to highlight that fact, to make it easier for the operators to read and not instigate the process at the wrong time!) which is where the difficulty lies. I am assuming that I will need a separate VBA function to step through each cell and compare the day date (ignoring time value.) in the previous cell, if day date is greater than 1 (as in not the following day.) insert a blank row.
I am looking for a solution to the following scenario but am struggling to get my head round it and would appreciate any guidance/ help anyone is able to provide.
Many thanks
You do not need a VBA Function for that, it can be accomplished with the function
A3 = IF(A2="",A1+31/24, IF(INT(A2+31/24)=INT(A2)+1,A2+31/24,""))
*For that to work, you will have to populate cells A1 and A2 manually, though.
You can use the INT() function to get the date part of a DateTime field, so it becomes simple to check if adding 31 hours will leave a 1 day gap in the sequence by checking INT(A2+31/24) = INT(A2)+1.
So, to explain the function, the part
IF(INT(A2+31/24)=INT(A2)+1,A2+31/24,"")
will check if the days are consecutive, and if so, it will fill the DateTime. If not, it will leave it blank.
The outer IF checks if the cell above is blank. If it is, the function will use the one above that.

Salesforce REST API get a list of updated records

I want to have a list of records under accounts object from a particular time to a particular time
say for example this my api query:
https://ax1.salesforce.com/services/data/v29.0/sobjects/Account/updated/?start=2015-06-30T06%3A49%3A00%2B00%3A00&end=2015-06-30T16%3A30%3A26%2B00%3A00
In my salesforce the time I have chosen is Indian Time which is UTC + 5:30
I created an account at 16:45 pm on 30th June in Indian time(as per salesforce this time is shown in the created by field of the account)
but for the above query in which I have chosen the start time and end time is 06:49 AM and 16:30 PM respectively
I got the record id which I have added at 16 45 pm Indian time but it shouldn't come in the response
The following is the response:
"ids": [
"0019000001QeOINAA3"
],
"latestDateCovered": "2015-06-30T09:00:00.000+0000"
}
Also the latestDateCovered it says 09 AM only
I don't understand this system
Could somebody help me on how this works?
The API REST API will be working with UTC DateTime values.
So you searched for records between:
2015-06-30 06:49:00 UTC
2015-06-30 16:30:26 UTC
Which I make to be:
2015-06-30 12:19:00 IST
2015-06-30 22:00:26 IST
So it would make sense that a record created at 16:45 pm on the 30th of June IST would appear in the results.
Try checking the SystemModStamp and LastModifiedDate fields in the API for the record in question, as the values will also be in UTC there.

Alias Dimension member value in SSAS

Is it possible to display or return a different value for an attribute in SSAS?
For example, in my date dimension I derive the business day within the month. Something like this:
DateId Date BusinessDay WeekDay
20120101 2012-01-01 01 Mon
20120102 2012-01-02 02 Tue
20120103 2012-01-03 03 Wed
20120104 2012-01-04 04 Thu
20120105 2012-01-05 05 Fri
20120106 2012-01-06 05 Sat
20120107 2012-01-07 05 Sun
02120108 2012-01-08 06 Mon
But the problem is every month has a 01 BusinessDay in it, so when I am creating a hierarchy for this, I get an error for duplicates. Also on the weekends I keep the business day constant.
So I need a way to have a unique BusinessDay value, but show a user friendly value. I was thinking I could concatenate the DateId + BusinessDay, but with an expression only show the Right 2 characters.
Making 2012010101 display as 01
Is this even possible? Maybe in the attributes properties somewhere?
I was able to accomplish this by doing the following:
I added two columns to the DSV. One for the value to be displayed, and a second for the true value. Next, I opened the Design view of the date dimension and added the attribute relationship just like adding any new attribute.
Now to make this work you have to open the attribute properties. and scroll all the way to the bottom and under the Source options update the KeyColumns to the actual value attribute. Next, in the same Source Options, update the NameColumn to the Display value you want.
It's actually pretty easy.

Sorting records based on modified timestamp?

I am trying to sort a list of records that have been created using a screen scraping script. The script adds the following style of date and time (timestamp) to each record:
13 Jan 14:49
The script runs every 15 minutes, but if I set the sort order to 'time DESC' it doesn't really make sense because it lists the records as follows:
13 Jan 14:49
13 Jan 12:32
13 Jan 09:45
08 Feb 01:10
07 Feb 23:31
07 Feb 06:53
06 Feb 23:15
As you can see, it's listing the first figure correctly (the day of the month in number form) but it's putting February after January. To add to the confusion it's putting the latest date in February at the top of the February section.
Is there a better way of sorting these so they are in a more understandable order?
If you are storing the values in a database, simply use the column type datetime when creating the field. The database will treat the field as time and will sort the values chronologically.
Otherwise, if you are storing the values elsewhere, for example in a flat file, convert the formatted time to unix time. Unix time is an integer, thus you can sort it easier.
Time.parse("13 Jan 09:45").to_i
# => 1326444300
Time.parse("08 Feb 01:10").to_i
# => 1328659800
You can always convert a unix time to a Time instance.
Time.at(1328659800).to_s
# => "2012-02-08 01:10:00 +0100"

Days Unavailable

I need a simple SQL to accomplish the below:
Problem:
When a petrol bunk runs out of fuel, the admin makes note of the DateTime (RunOutDate) when it ran out of fuel and notes also the DateTime (ResupplyDate) when the fuel supply was back on.
I need to create a report on how many days the bunk ran out of fuel.
eg.
1/1/1 10:10 to 1/1/1 10:50 should be counted as 1
1/1/1 10:10 to 2/1/1 07:20 should be counted as 2
1/1/1 23:55 to 2/1/1 00:10 should be counted as 2
I can not bank using hours using DateDiff as 24 hours could have spanned across 2 days.
TIA
DATEDIFF(d, RunOutDate, ResupplyDate) + 1
Remember that DATEDIFF always counts the number of BOUNDARIES that you cross. For days (first argument d), it counts the number of times the clock passed midnight. So to count the number of days covered you just add 1.
DATEDIFF using day, then add 1.
DATEDIFF uses the midnight to count days so you'll get 0, 1, 1 for each example above. Then add 1.
DATEDIFF(day, '16 Dec 2008 10:10', '16 Dec 2008 10:50') + 1