SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


calculate Excess/Short and show in one row


calculate Excess/Short and show in one row

Author
Message
immaduddinahmed
immaduddinahmed
SSC-Enthusiastic
SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)SSC-Enthusiastic (153 reputation)

Group: General Forum Members
Points: 153 Visits: 420
this is my data


date---------------------------eid-------------timein-------------------------timeout--------------spend-----excess short
2013-01-04 00:00:00.000--26446--2013-06-11 09:44:00.000--2013-06-11 13:20:00.000--08:06:00------5:24
2013-01-04 00:00:00.000--26446--2013-06-11 13:56:00.000--2013-06-11 18:26:00.000--NULL------------4:30



i want to add excess short column and show in one row

this is what i want


date---------------------------eid-------------timein-------------------------timeout--------------spend-----excess short
2013-01-04 00:00:00.000--26446--2013-06-11 09:44:00.000--2013-06-11 13:20:00.000--08:06:00-------00:54
2013-01-04 00:00:00.000--26446--2013-06-11 13:56:00.000--2013-06-11 18:26:00.000--NULL------------NULL



i calculate excess short time from timein and timeout


this is my query


select
[date],
min([Timein]) as First_Record,
sum(DATEDIFF(ss, [Timein], [Timeout])) as Time_In_Seconds
into #temp1 from ATTEND_LOG
where eid=26153
group by [date]
GO
select
t.[date],
t.eid,
t.[Timein] timein,
t.[Timeout]timeout,
CONVERT(VARCHAR(8), DATEADD(ss, Time_In_Seconds, 0), 108) AS SpendTime,
CAST (ABS( convert(varchar(10),540,108) - DATEDIFF (MINUTE, t.Timein, t.timeout ) ) / 60 as varchar ) + ':' + -- Hours ( + ':' separator )
CAST (ABS (convert(varchar(10),540,108) - DATEDIFF (MINUTE, t.Timein, t.timeout ) ) % 60 as varchar ) as excesshorttime
FROM ATTEND_LOG t
left join #temp1 t2 on t.[date]=t2.[date] and t.[Timein] = t2.First_Record
where eid=26446


help me out please
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search