Calculating fractions of hours from time date range
Hello friends,
I'm using sql server 2008 r2 and I have a table called attendance with the following fields
attendance_no int
attendance_date date
attendance_timein time(7)
attendance_timeout time(7)
emp_id int
and another table called employee with the following fields
emp_id int
emp_name varchar(50)
emp_tel varchar(50)
I need to calculate the total minutes worked as well as total hours worked for each employee with in a specified date range and I created the below query which working fine but it is not calculating the fractions of hours, I mean when an employee works
for example 7 and half hours, its showing just 7 hours instead of 7.5 hours.
SELECT a.attendance_date As 'Date',e.emp_id As 'ID',e.emp_name As 'Name',e.emp_tel As 'Telephone',left(a.attendance_timein,8)[Time in],left(a.attendance_timeout,8)[Time out],
+ CAST(DATEDIFF(second, attendance_timein, attendance_timeout) / 60 AS NVARCHAR(50)) As 'Total minutes',
CAST(DATEDIFF(second,attendance_timein,attendance_timeout) / 60 /60 % 60 AS NVARCHAR(50)) As 'Total hours'
from attendance a join employee e on e.emp_id=a.emp_id and a.attendance_date between '2014-11-06' and '2014-11-08' and e.emp_tel='65098009'
I would appreciate any help about this.
Thanks in advance
Mohamoud
If I understand correctly, according to
Mohamoud's data sample, there is already Total minutes in the input (the above
table Mohamoud posted)
and all he need is a simple convert to decimal and the divided by 60.
select [Total minutes] / 60.c
Mohamoud,
is that correct?
The result show that you might need some rounding. for example 31/60 is 0.516666 while you show us 0.5
Please clarify if you need rounding and how many characters after the dot you need (this can be done using declaring decimal(x,y), converting, or multipla and using floor function, etc')
Ronen Ariely
[Personal Site] [Blog] [Facebook]
Similar Messages
-
Recently my iphone is consuming too much data, I have installed a data monitoring app and I found that - although I turned off all notifications and push email - push services is using around a 1mega/hour from cellular data (even if I am using wi-fi) !!!
cpupower frequency-info
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which run at the same hardware frequency: 0 1 2 3
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 10.0 us.
hardware limits: 800 MHz - 2.30 GHz
available frequency steps: 2.30 GHz, 2.30 GHz, 1.80 GHz, 1.60 GHz, 1.40 GHz, 1.20 GHz, 1000 MHz, 800 MHz
available cpufreq governors: conservative, powersave, ondemand, performance
current policy: frequency should be within 800 MHz and 2.30 GHz.
The governor "conservative" may decide which speed to use
within this range.
current CPU frequency is 800 MHz.
cpufreq stats: 2.30 GHz:0,02%, 2.30 GHz:0,05%, 1.80 GHz:0,05%, 1.60 GHz:0,03%, 1.40 GHz:0,01%, 1.20 GHz:0,16%, 1000 MHz:0,38%, 800 MHz:99,29% (1017)
boost state support:
Supported: yes
Active: yes
25500 MHz max turbo 4 active cores
25500 MHz max turbo 3 active cores
25500 MHz max turbo 2 active cores
25500 MHz max turbo 1 active cores
Thax -
Can't subtract from time,date, can only add
I've been having some trouble with times and dates. I wanted to perform a time correction calculation, that is, to find the difference between two times, then add the difference to a third time as a way of "correcting" it. So, you can add and subtract time-date values in Numbers, and you get the difference in a decimal fraction of days. That is, a day is 1, a half a day is .5, etc. This is the same way Excel does things. So far so good.
The problem is that, for some reason, you can add to data-time values, but not subtract. For example:
2/27/2008 9:30:00 PM + .01 = 2/27/2008 9:44:00 PM
great, no problem, but...
2/27/2008 9:30:00 PM - .01 = 2/27/2008 9:30:00 PM
Huh? Why can't I subtract? What's even stranger is that it works of you do this:
2/27/2008 9:30:00 PM + (-.01) = 2/27/2008 9:15:00 PM
No that's messed up. Subtraction fails but adding a negative number works? This is a crazy bug.Hello
For the add/substract a constant, my first guess was quite simple.
The parser is defined to accept the operator + not the operator -.
If it finds a +, is parse the parameter which may be positive or negative.
If it finds a -, it treats it as a "not allowed" one.
Alas it's a wrong description.
If I try to add 1.1, it works.
If I try to substract 1.1, the integer part is substracted, not the decimal part.
So, it can't be a feature but a bug.
I'm a bit reluctant to report it because I'm afraid that the result would be : disable the tip fooling the beast with a fake addition.
What's your advice ? -
Date deviates from Due Date range??
Hi All,
When i'm trying to add a back dated A/R Invoice, I'm getting an error message that the date deviates from the due date range. I have selected the appropriate posting period for this and also have checked the document numbering. In the Journal entry, i can see that the due date is 02/04/09 where as in the A/R Invoice, i have given the due date as 29/03/09. Now is this the reason for this error? Any suggestions??
Thanks in advance,
JosephDouble check your period setting, Due Date From and To must cover the Due date for the document you are posting. Document Date From and To range should be good too.
Thanks,
Gordon -
How to exclude weekends & holidays from a date range
Hi Friends,
How can I exclude weekends & other holidays (which are specific to that country only) from a given range of date (if any weenends or holiday falls in that range)?
Please supply some sample code if possible.
Thanks in advance.Enayats_screen wrote:
Hi
I have found the relevant code for your help. May be this will solve your purpose. Please visit the below link
http://www.simplyshareit.net/itemDetails.jsf?q=532&
Thanks.Whew! Thank the gods you saved the OP from having to actually think or learn or clearly communicate his problem! -
Infopath to Sharepoint: Create multiple list items from a date range?
Hi everyone! I have a request from a client to create a SharePoint/InfoPath form that has Start Date and End Date fields. Their request is that when submitted it will make a separate entry for each day in the date range. For example:
John Doe is out from 4/1 - 4/3. When submitted it will make an entry that he was out 4/1, 4/2, and 4/3. this is requested due to them wanting to have a SharePoint list that shows all the day and not use a calendar.
This question was previously posted on another forum by another individual a year ago with no responses so I'm hoping for better results then he got lol.
Any ideas or pointing me in the right direction in terms of how to begin this would be greatly appreciated!
Thanks in advance and I hope everyone is having a great day!I've been asked for things like this in the past too but never found a good solution.
The closest i could think of would be to create a workflow that loops between the two dates and creates an entry for each one (of a different content type) then deletes the inital content entry. I haven't done this so i'm not sure if it's possible without
custom SPD actions. -
Function to list the month from a date range?
I would like to know what the function is that would take a look at a date range, and extract the month name
Here is how I would like it to come out:Hello
The following sample tables are along your original scheme using month name to filter the data.
2014 (excerpt)
A1 month
A2 =MONTHNAME(MONTH(B2))
A3 =MONTHNAME(MONTH(B3))
A4 =MONTHNAME(MONTH(B4))
B1 date
B2 2013-01-15
B3 2013-01-20
B4 2013-01-27
C1 category
C2 A
C3 B
C4 C
D1 amount
D2 100
D3 50
D4 20
January
A1 category
A2 A
A3 B
A4 C
A5 D
A6 E
A7 F
A8 G
A9 H
B1 totals
B2 =SUMIFS(2014::D,2014::A,C$1,2014::C,A2)
B3 =SUMIFS(2014::D,2014::A,C$1,2014::C,A3)
B4 =SUMIFS(2014::D,2014::A,C$1,2014::C,A4)
B5 =SUMIFS(2014::D,2014::A,C$1,2014::C,A5)
B6 =SUMIFS(2014::D,2014::A,C$1,2014::C,A6)
B7 =SUMIFS(2014::D,2014::A,C$1,2014::C,A7)
B8 =SUMIFS(2014::D,2014::A,C$1,2014::C,A8)
B9 =SUMIFS(2014::D,2014::A,C$1,2014::C,A9)
C1 January
C2
C3
C4
C5
C6
C7
C8
C9
Notes.
Formula in January::B2 can be filled down across B2:B9.
The target month name is defined in January::C1.
February table is the same as January table except for the value in C1.
And the following sample tables are using date per se instead of month name to filter the data. In this scheme, you don't need month column in source table but the retrieving formulae in destination table become more complex.
2014 (excerpt)
A1 date
A2 2013-01-15
A3 2013-01-20
A4 2013-01-27
B1 category
B2 A
B3 B
B4 C
C1 amount
C2 100
C3 50
C4 20
January
A1 category
A2 A
A3 B
A4 C
A5 D
A6 E
A7 F
A8 G
A9 H
B1 totals
B2 =SUMIFS(2014::C,2014::B,A2,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B3 =SUMIFS(2014::C,2014::B,A3,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B4 =SUMIFS(2014::C,2014::B,A4,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B5 =SUMIFS(2014::C,2014::B,A5,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B6 =SUMIFS(2014::C,2014::B,A6,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B7 =SUMIFS(2014::C,2014::B,A7,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B8 =SUMIFS(2014::C,2014::B,A8,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
B9 =SUMIFS(2014::C,2014::B,A9,2014::A,">="&EOMONTH(C$1,-1)+1,2014::A,"<="&EOMONTH(C$1,0))
C1 2013-01-01
C2
C3
C4
C5
C6
C7
C8
C9
Notes.
Formula in January::B2 can be filled down across January::B2:B9.
The target month is defined in January::C1, which can be any date in target month, e.g., 2013-01-01, 2013-01-20, etc. The formulae in B will retrieve data with date in range: 2013-01-01 <= [date] <= 2013-01-31.
February table is the same as January table except for the value in C1.
Tables are built in Numbers v2.
Hope this may help,
H
EDIT: Replaced the last table with the correct one. (Formulae in B are correct) -
Calculations for 6 months from todays date
Need to calculate the total of all the months starting from today's date for the next 6 months from the current date.
For ex
Month Total
01.07.2008 10
01.08.2008 20
01.09.2008 50
01.10.2008 72
01.11.2008 85
01.12.2008 15
Please advice how to work on this.
Can we use ranges?
Thanks in advance.Hi dolly,
Ref this code.....
TYPE-POOLS :
slis.
TABLES :
pernr.
INFOTYPES :
0000,
0001,
0002.
TYPES :
BEGIN OF t_final,
srlno TYPE i, "Serial No
pernr TYPE p0000-pernr, "Employee No
vorna TYPE p0002-vorna, "First Name
nachn TYPE p0002-nachn, "Last Name
btrtl TYPE p0001-btrtl, "PERSONAL SUB AREA / SEGMENT
btext TYPE t001p-btext, " SEGMENT DESC
begda TYPE p0000-begda, " JOINING DATE
pdate TYPE p0000-begda, " Probation period date.
END OF t_final,
BEGIN OF t_t001p,
btrtl TYPE t001p-btrtl,
btext TYPE t001p-btext,
END OF t_t001p.
DATA :
v_year(4) TYPE n,
v_year1 TYPE i,
count TYPE i,
v_mont(2) TYPE n,
v_dt(2) TYPE n,
v_date(8),
it_final TYPE STANDARD TABLE OF t_final,
it_temp TYPE STANDARD TABLE OF t_final,
it_t001p TYPE STANDARD TABLE OF t_t001p,
wa_t001p TYPE t_t001p,
wa_temp TYPE t_final,
wa_final TYPE t_final.
ALV Grid Declarations *
DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat,
wa_layout TYPE slis_layout_alv,
it_sortcat TYPE slis_t_sortinfo_alv,
wa_sortcat LIKE LINE OF it_sortcat.
START-OF-SELECTION.
PERFORM fill_itabs.
GET pernr.
rp-provide-from-frst p0000 space '18000101' '99991231'.
IF pnp-sw-found = 1.
IF p0000-stat2 = 3. " Checking for status.
MOVE :
p0000-begda TO wa_temp-begda,
p0000-pernr TO wa_temp-pernr.
rp-provide-from-last p0001 space pnpbegda pnpendda.
IF pnp-sw-found = 1.
MOVE :
p0001-btrtl TO wa_temp-btrtl.
CLEAR : wa_t001p.
READ TABLE it_t001p INTO wa_t001p WITH KEY btrtl = wa_temp-btrtl.
IF sy-subrc = 0.
MOVE : wa_t001p-btext TO wa_temp-btext.
ENDIF.
ENDIF.
rp-provide-from-last p0001 space pnpbegda pnpendda.
IF pnp-sw-found = 1.
MOVE :
p0002-vorna TO wa_temp-vorna,
p0002-nachn TO wa_temp-nachn.
ENDIF.
APPEND wa_temp TO it_temp.
CLEAR : wa_temp.
ENDIF. "if p0000-stat2 = 3.
ENDIF. "if pn-sw-found = 1.
END-OF-SELECTION.
PERFORM process_data.
PERFORM build_catalog.
PERFORM display_data.
*& Form PROCESS_DATA
text
--> p1 text
<-- p2 text
FORM process_data .
LOOP AT it_temp INTO wa_temp.
IF wa_temp-begda+4(2) > 6.
v_year = wa_temp-begda(4) + 1.
v_mont = wa_temp-begda+4(2) + 6.
v_dt = wa_temp-begda+6(2).
IF WA_TEMP-BEGDA+4(2) = '08'.
IF wa_temp-begda+6(2) = '29' OR
wa_temp-begda+6(2) = '30' OR
wa_temp-begda+6(2) = '31'.
v_dt = '28'.
ENDIF.
ENDIF.
IF v_mont > 12.
v_mont = v_mont - 12.
CONCATENATE v_year v_mont v_dt INTO v_date.
MOVE : v_date TO wa_temp-pdate.
ENDIF.
ELSE.
v_mont = wa_temp-begda+4(2) + 6.
CONCATENATE wa_temp-begda(4) v_mont wa_temp-begda6(2) INTO v_date.
wa_temp-pdate = v_date.
ENDIF.
MODIFY it_temp FROM wa_temp .
CLEAR : v_date, v_year, v_mont.
ENDLOOP.
LOOP AT it_temp INTO wa_temp WHERE pdate BETWEEN pnpbegda AND pnpendda.
MOVE : wa_temp-pernr TO wa_final-pernr,
wa_temp-vorna TO wa_final-vorna,
wa_temp-nachn TO wa_final-nachn,
wa_temp-begda TO wa_final-begda,
wa_temp-btrtl TO wa_final-btrtl,
wa_temp-btext TO wa_final-btext.
CASE wa_temp-pdate+4(2).
WHEN '04' OR '06' OR '09' OR '11'.
IF wa_temp-pdate+6(2) > '30'.
CONCATENATE wa_temp-pdate(4) wa_temp-pdate4(2) '30' INTO v_date.
MOVE : v_date TO wa_final-pdate.
ELSE.
MOVE wa_temp-pdate TO wa_final-pdate.
ENDIF.
WHEN '02'.
v_year1 = wa_temp-pdate+(4) MOD 4.
IF v_year1 = 0 AND wa_temp-pdate+6(2) > '29'.
CONCATENATE wa_temp-pdate(4) wa_temp-pdate4(2) '29' INTO v_date.
MOVE : v_date TO wa_final-pdate.
ELSEIF v_year1 NE 0 AND wa_temp-pdate+6(2) > '28'.
CONCATENATE wa_temp-pdate(4) wa_temp-pdate4(2) '28' INTO v_date.
MOVE : v_date TO wa_final-pdate.
ELSE.
MOVE wa_temp-pdate TO wa_final-pdate.
ENDIF.
WHEN OTHERS.
MOVE wa_temp-pdate TO wa_final-pdate.
ENDCASE.
count = count + 1.
MOVE : count TO wa_final-srlno.
APPEND wa_final TO it_final.
CLEAR : wa_final, v_year1 , v_date.
ENDLOOP.
ENDFORM. " PROCESS_DATA
*& Form BUILD_CATALOG
FORM build_catalog .
DEFINE m_fieldcat.
add 1 to wa_fieldcat-col_pos.
wa_fieldcat-fieldname = &1.
wa_fieldcat-tabname = 'IT_FINAL'.
wa_fieldcat-seltext_m = &2.
wa_fieldcat-outputlen = &3.
append wa_fieldcat to it_fieldcat.
END-OF-DEFINITION.
m_fieldcat 'SRLNO' 'S No' '8' .
m_fieldcat 'PERNR' 'Employee No' '15'.
m_fieldcat 'VORNA' 'First Name' '15' .
m_fieldcat 'NACHN' 'Last Name' '15' .
m_fieldcat 'BTRTL' 'Segment' '15' .
m_fieldcat 'BTEXT' 'Segment Desc' '15' .
m_fieldcat 'BEGDA' 'Date of Joining' '15'.
m_fieldcat 'PDATE' 'Probation End Date' '15' .
ENDFORM. " BUILD_CATALOG
*& Form DISPLAY_DATA
FORM display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = it_fieldcat
it_sort = it_sortcat
TABLES
t_outtab = it_final.
ENDFORM. " DISPLAY_DATA
*& Form FILL_ITABS
FORM fill_itabs .
SELECT btrtl
btext
FROM t001p
INTO TABLE it_t001p.
ENDFORM. " FILL_ITABS -
Calculating Previous Month(s) From Current Date
Greeting JavaScripting Gurus!
I would like to ask for some assistance on Date Calculation.
Here is my current scenario:
The user inputs a date mm/dd/yyyy ("DateField")
The powers that be over here are asking for the "DateField" to then calculate these items:
"DateField" minus(-) 12 months = mm/yyyy ("12MonthsAgoDateField")
"DateField" minus(-) 18months = mm/yyyy ("18MonthsAgoDateField")
"DateField" minus(-) 36 months = mm/yyyy ("36MonthsAgoDateField")
and so on...
I've read some of the Date Calculation posts, but could no seem to find anything that fit this scenario.
I freely confess my javascripting ability is very minor.
I would greatly appreciate any help in scripting this.
Thank you!Unfortunately the numbers of days in a month or year are not the same for all months or years, so the get and set date methods might not work. Fortunately there are the getMonth() and setFullYear() methods for getting or setting the month or year for a given date.
For the "On Blur" action for the "DateField" you can use:
function GetField(cName) {
// get a field object with error catching;
var oField = this.getField(cName);
if(oField == null) app.alert("Error accessing field named: " + cName, 0, 0);
return oField;
} // end GetField function;
function AddMonths(oDate, nMonths) {
// add nMonths to oDate object;
oDate.setMonth(oDate.getMonth() + nMonths);
return oDate; // return adjusted date object;
} // end AddMonths;
function Scand(cFormat, cDate) {
var oDate = util.scand(cDateFormat, event.value);
if(oDate == null) app.alert("Error converting " + oDate.valueAsString + " with format: " + cDateFormat, 0, 0);
return oDate;
} // end Scand functon;
var cDateFormat = "mm/dd/yyyy"; // format for date strings;
// event value is the start date string;
// 12 months ago;
var o12MonthsAgo = GetField("12MothsAgoDateField")
var oDate = Scand(cDateFormat, event.value);
oDate = AddMonths(oDate, -12) // subtract 12 months;
o12MonthsAgo.value = util.printd(cDateFormat,oDate);
// 18 months ago;
var o18MonthsAgo = GetField("18MothsAgoDateField")
oDate = Scand(cDateFormat, event.value);
oDate = AddMonths(oDate, -18) // subtract 18 months;
o18MonthsAgo.value = util.printd(cDateFormat, oDate);
// 36 months ago;
var o36MonthsAgo = GetField("36MothsAgoDateField")
oDate = Scand(cDateFormat, event.value);
oDate = AddMonths(oDate, -36); // subtract 36 months;
o36MonthsAgo.value = util.printd(cDateFormat, oDate);
// and so on;
Since getting a field object, converting a date string to a date object and adjusting the date object using the getMonth and setMonth methods are repeated several times I have used functions so the repeated code could be reused. -
Capturing results from a date range where dates are concatenated with text
my issue_code column has results = OK and the date. An example would be OK20071001 where the last 8 digits is in the YYYYMMDD format.
How can i calculate the # of PO#s that had OK as their issues during a given month.
The sql below shows what i had but i get an error:
SELECT count(unique(SAP_PO_NUMBER)
FROM VENDOR_PURCHASE_ORDER
WHERE SUBSTR(ISSUE_CODE,3,8) BETWEEN
TO_CHAR('20071001', 'YYYYMMDD') AND TO_CHAR('20071101', 'YYYYMMDD')
AND ISSUE_CODE LIKE 'OK%'I'm usually a fan of TO_DATE transformation myself. However in this case I don't feel it is neccessary. The column is already in VARCHAR2 and has a dateformat in an ordered fashion.
why not simply do this:
SELECT count(distinct SAP_PO_NUMBER)
FROM VENDOR_PURCHASE_ORDER
WHERE ISSUE_CODE LIKE 'OK200710%';This statement won't raise an error when skrewed date values are in this column. But I'm not sure if this realy is possible and which version is wanted.
'OK20071043' => Should this result in an error or not?
Message was edited by:
Sven Weller -
Results for a period of time (date range)
Hi,
Could you please help me with the following:
SELECT a.lot AS LotNumber, a.codeart AS ItemCode, sum(a.quantity), a.unit AS Unit, a.datetrace AS Dates FROM Production.pps_lotstraces a
WHERE a.codeart LIKE '886%' OR a.codeart LIKE '997%') and (a.datetrace between to_date('20100105','YYYYMMDD') and sysdate)
GROUP BY a.lot, a.codeart, a.unit, a.datetrace
ORDER BY a.lot, a.datetrace
The only issue I have with this query is that when it is run I get following message
ORA-01861 - literal does not match format string. This is related to the fact that the date is stored as a string.
The query should look at the dates from the beginning of the year up to today which is a system date.
Could you please advise how this issue can be resolved?
Thank you in advance for your help
Regardsuser12866679 wrote:
SELECT a.lot AS LotNumber, a.codeart AS ItemCode, sum(a.quantity), a.unit AS Unit, a.datetrace AS Dates FROM Production.pps_lotstraces a
WHERE a.codeart LIKE '886%' OR a.codeart LIKE '997%') and (a.datetrace between to_date('20100105','YYYYMMDD') and sysdate)
GROUP BY a.lot, a.codeart, a.unit, a.datetrace
ORDER BY a.lot, a.datetrace
SELECT a.lot AS LotNumber, a.codeart AS ItemCode, sum(a.quantity), a.unit AS Unit, a.datetrace AS Dates
FROM Production.pps_lotstraces a
WHERE a.codeart LIKE '886%' OR a.codeart LIKE '997%') and (a.datetrace between to_date('20100105','YYYYMMDD') and sysdate)
^
|
|
you have closing parenthesis but you don't have an opening parenthesis
GROUP BY a.lot, a.codeart, a.unit, a.datetrace
ORDER BY a.lot, a.datetraceaside from the missing opening parenthesis what is the datatype for your column a.codeart and a.datatrace? -
Calculation of relative position from dynamic data
I have developed this code for plotting the voltage from the PSD(Position Sensitive detector) in terms of position in LabVIEW. It gives me the exact map of the position of the LASER beam on the PSD, on the graph in LabVIEW.
Now what I need to do is calculate out the relative displacement between two positions of the spot. Suppose at time t1 the position is at A(x1,y1) and then at time t2 it moves to B(x2,y2). I know the mathematical formula for the displacement from A to B.
But my problem is how do I get the values of (x2,y2) and the previous position value of (x1,y1) dynamically. I need to do this continously al long as the experiment gos on and then also save it.
Thank You for the help.
Attachments:
Untitled_3.vi 344 KBBurhanuddin wrote:
Thank You for the reply Sir, but the problem is how do i compare the values of x,y. I am not able to extract the vales from the graph/array for 2 consequtive times.
After you use the 'Split signal' function, right after your 'DAQ Assistant', you should have a signal of X values, and one of Y values.
Convert each of these signals to type DBL. They should now be 1D arrays of type DBL.
Then, you can do the following, since For Loops auto-index:
Edit: In my example, I switched the X and Y inputs ,
however, in this circumstance, it doesnt matter for the formula used.
Either way, in your VI you could correct that if you want.
Message Edited by Cory K on 03-27-2009 11:56 AM
Cory K
Attachments:
XY arrays.PNG 9 KB -
Get months from a date range comparing event date
Hi All,
Below is the data
CREATE TABLE #Coverage(
EmployeeID INT,
EmployeeName VARCHAR(20),
CoverageName VARCHAR(50),
CoverageAmount Decimal,
CoveredBy VARCHAR(20),
EventDate DATETIME,
CoverageStartDate DATETIME,
CoverageEndDate DATETIME
INSERT INTO #coverage VALUES (8,'Lara','Employee + Children',213.60,'EmployeeContribution','2013-10-01','2013-10-01','2014-05-31'),
(8,'LAra','Employee + Children', 606.31 ,'CompanyContribution' ,'2013-10-01','2013-10-01','2014-05-31'),
(8,'LAra','Employee Only' ,0.00 ,'EmployeeContribution' ,NULL ,'2013-06-01','2014-05-31'),
(8,'LAra','Employee Only' ,431.55 ,'CompanyContribution' ,NULL ,'2013-06-01','2014-05-31'),
(8,'LAra','Employee Only' ,81.42 ,'EmployeeContribution' ,NULL ,'2012-06-01','2013-05-31'),
(8,'LAra','Employee Only' ,420.93 ,'CompanyContribution' ,NULL ,'2012-06-01','2013-05-31')
SELECT * FROM #Coverage
drop table #coverage
and expected out put for the year 2013
EmployeeID
EmployeeName
CoverageName
CoverageAmount
CoveredBy
Month
Year
8
Lara
Employee Only
81
Employee Contibution
1
2013
8
Lara
Employee Only
421
Company Contribution
1
2013
8
Lara
Employee Only
81
Employee Contibution
2
2013
8
Lara
Employee Only
421
Company Contribution
2
2013
8
Lara
Employee Only
81
Employee Contibution
3
2013
8
Lara
Employee Only
421
Company Contribution
3
2013
8
Lara
Employee Only
81
Employee Contibution
4
2013
8
Lara
Employee Only
421
Company Contribution
4
2013
8
Lara
Employee Only
81
Employee Contibution
5
2013
8
Lara
Employee Only
421
Company Contribution
5
2013
8
Lara
Employee Only
81
Employee Contibution
6
2013
8
Lara
Employee Only
421
Company Contribution
6
2013
8
Lara
Employee Only
81
Employee Contibution
7
2013
8
Lara
Employee Only
421
Company Contribution
7
2013
8
Lara
Employee Only
81
Employee Contibution
8
2013
8
Lara
Employee Only
421
Company Contribution
8
2013
8
Lara
Employee Only
81
Employee Contibution
9
2013
8
Lara
Employee Only
421
Company Contribution
9
2013
8
Lara
Employee +Children
214
Employee Contibution
10
2013
8
Lara
Employee +Children
606
Company Contribution
10
2013
8
Lara
Employee +Children
214
Employee Contibution
11
2013
8
Lara
Employee +Children
606
Company Contribution
11
2013
8
Lara
Employee +Children
214
Employee Contibution
12
2013
8
Lara
Employee +Children
606
Company Contribution
12
2013
Can any one help me out with this.
Thanks!This gives your resultset.
I've added the cte to give a newenddate because your dataset doesn't close off the previous one in all cases and gave duplicates - you can remove this if it is a mistake in the data. Also you would need to add the employee to the partition to run on multiple
employees.
declare
@Coverage TABLE (
EmployeeID
INT,
EmployeeName
VARCHAR(20),
CoverageName
VARCHAR(50),
CoverageAmount
Decimal,
CoveredBy
VARCHAR(20),
EventDate
DATETIME,
CoverageStartDate
DATETIME,
CoverageEndDate
DATETIME
INSERT
INTO @Coverage
VALUES (8,'Lara','Employee + Children',213.60,'EmployeeContribution','2013-10-01','2013-10-01','2014-05-31'),
(8,'LAra','Employee
+ Children', 606.31
,'CompanyContribution'
,'2013-10-01','2013-10-01','2014-05-31'),
(8,'LAra','Employee
Only'
,0.00 ,'EmployeeContribution'
,NULL ,'2013-06-01','2014-05-31'),
(8,'LAra','Employee
Only'
,431.55
,'CompanyContribution'
,NULL ,'2013-06-01','2014-05-31'),
(8,'LAra','Employee
Only'
,81.42 ,'EmployeeContribution'
,NULL ,'2012-06-01','2013-05-31'),
(8,'LAra','Employee
Only'
,420.93
,'CompanyContribution'
,NULL ,'2012-06-01','2013-05-31')
SELECT
* FROM
@Coverage
;with
ctee1 as
select
*, seq
= row_number()
over (partition
by coveredby
order by coveragestartdate)
from
@Coverage
,ctee
as
select
c1.*,
newenddte = coalesce(c2.coveragestartdate-1,
c1.coverageenddate)
from
ctee1 c1
left
join ctee1
c2
on
c1.coveredby
= c2.coveredby
and
c1.seq
= c2.seq-1
cte1 as
select
dtestrt =
convert(datetime,'20130101'),
dteend =
convert(datetime,'20131201')
,cte
as
select
dtestrt =
cte1.dtestrt,
dteend =
dateadd(mm,1,cte1.dtestrt)-1,
mth =
month(cte1.dtestrt),
yr =
year(cte1.dtestrt)
from cte1
union
all
select
dtestrt =
dateadd(mm,1,cte.dtestrt),
dteend =
dateadd(mm,2,cte.dtestrt)-1,
mth =
month(dateadd(mm,1,cte.dtestrt)),
yr =
year(dateadd(mm,1,cte.dtestrt))
from cte,
cte1 where
cte.dtestrt
< cte1.dteend-1
select
c.EmployeeID,
c.EmployeeName,
c.CoverageName,
c.CoverageAmount,
c.CoveredBy,
cte.mth,
cte.yr,
cte.dtestrt,
cte.dteend
from
cte
join
ctee c
on
cte.dtestrt
<= c.newenddte
and cte.dteend
>= c.CoverageStartDate
order
by c.EmployeeID,
cte.dtestrt -
How to Calculate Total Worked Hours in a date range
<p><span>WorkedHours column type is varchar(8) (for HH:MM:SS), <br />how to sum working hours of an employee for every month.</span> <br /></p><p><span>ex. of data : WorkedHours<br /><br />attencode attendate WorkedHours<br />1573 20-01-2007 07:34:22<br />1573 21-01-2007 12:31:10<br /><br />how can i sum the WorkedHours and print it in Hours format.<br />(like 20.17 for this 2 values)<br /><br />Can u able to follow me.<br />If not pls. feel free to get more information in this regard.</span></p>
Create a formula like this :
((hour({tmpDate.attendate }) * 60 * 60) +
(minute({tmpDate.attendate }) * 60) +
Second({tmpDate.attendate }))/3600
and then take the Sum of it. You can get the result.
logic behind this is all the hours and minutes are converted into seconds and then added and divided by 3600 to get the actual hours.
thanks
kanak -
Time calculation from one date to some other date
Hello,
I want to time calcualtion from one date to other date period.
for calculating total hr's from one date to other date.plz let me know the logic.
Date Time
Eq: 1st date: 22.05.2008 01.10.00
2nd date: 25.05.2008 12.10.00
I want the total hrs from 22.05 to 25.05 like i need result as
from 22 to 25 total hrs based on the time given.Hello,
Instead of FM..We can achieve by the following program...
REPORT YRT_TEST1.
parameters : date1 like sy-datum,
date2 like sy-datum.
data: days(3) type n.
data: years(10) type p decimals 3.
start-of-selection.
days = date2 - date1.
years = days / 365.
write: / days,
years.
Now Multiply 24 to days to get hours and the multiply with 60*60 to get the seconds
***************Reward points,if found useful
Maybe you are looking for
-
Adding iPhoto stills to iMovie, Adding iPhoto stills to iMovie
Working with the new versions of iMovie, iPhoto - when I select a photo from iPhoto library (in iMovie) and drag it too the time-line - i get a circle with a slash mark icon - and it won't allow me to add the photo. When I select a photo from Apertu
-
WRT54G ver8.00.03 questions PLEASE HELP
Im using the WRT54G ver.8.00.03 router as a wired router. I was wondering if I can use this router for xbox 360 live? I hooked it up to my xbox 360 and paid for xbox live and I did the xbox live test and everything came back as good to go. The system
-
Use of ADOBE form with Workflow...
Hi All, Can you help to understand the integration between ADOBE forms and Workflow? I want to understand how to use ADOBE forms with workflow? and in which scenario's we can use it? Regards, Yogesh
-
Error when trying to give permissions to users and adding them to the site
Hi, i'm facing an issue with a public website (SharePoint server 2010) where i can't add any users (windows users) or grant permission for them. I checked the Authentication Provider for the web application and Windows Authentication NTLM is enabled,
-
I have several skype groups. I make daily calls to the groups. Some days people are on vacation - or don't need to be in the group call. There is not a consistent way to remove a person from a group. Sometimes in the Right-Click menu I get the