how to caluculate half day

  • hi

    i want to caluclate half day

    my actual data is like this

    date-----------------------------eid---------------timein---------------------------timeout-----------spend-----excessshort------excess

    2013-03-21 00:00:00.000---26446---2013-06-13 09:13:00.000--2013-06-13 3:46:00.000----06:33:00---- 02:27:00-------Short

    i want this data

    date-----------------------------eid---------------timein---------------------timeout-----------spend-----excessshort-excess----Remarks

    2013-03-21 00:00:00.000--26446--2013-06-13 09:13:00.000--2013-06-13 3:46:00.000-06:33:00--02:27:00---Short------HALFDAY

    employee timing is 9am to 6pm if he leaves from factory at 4pm or before 4 pm then remarks say halfday

    becouse we have 2 hours half day mean if he go for some work and didnt come back for 2 hours our more then 2 hours then half day implemented

    please implement on this query

    drop table #temp1

    select

    [date],

    min([Timein]) as First_Record,

    sum(DATEDIFF(minute, [Timein], [Timeout])) as Time_Minutes

    into #temp1 from attend_LOG

    where eid = 17090

    group by [date]

    GO

    select

    t.[date],

    t.eid,

    t.[Timein] as timein,

    t.[Timeout] as timeout,

    CONVERT(VARCHAR(8), DATEADD(minute, Time_Minutes, 0), 108) AS SpendTime,

    case when (540 - Time_Minutes) > 0 Then '- ' else '+ ' end

    +CONVERT(VARCHAR(8), DATEADD(minute, ABS(540 - Time_Minutes), 0), 108) as excesshorttime

    FROM attend_LOG t

    left join #temp1 t2 on t.[date] = t2.[date] and t.[Timein] = t2.First_Record

    where eid = 17090

    order by t.[date], t.[Timein]

    please help me out

    thanks for the help

    immad

  • In order to help we will need a few things:

    1. Sample DDL in the form of CREATE TABLE statements

    2. Sample data in the form of INSERT INTO statements

    3. Expected results based on the sample data

    Please take a few minutes and read the first article in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply