Click here to Skip to main content
16,018,904 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello,
I have one table like,..
Break and column name
BreakId bigint pk,BreakTypeIn int,BreakTimeIn datetime,BreakTypeOut int,BreakTimeOut
datetime,CreateDateTime,UpdateDateTime.

on date 26/10/2016 two record are there.like
BreakId BreakTypeIn BreakTimeIn BreakTypeOut BreakTimeOut CreateDateTime
1 1 12:03 2 12:13 2016-10-19 12:03:55.350
2 1 12:44 2 12:48 2016-10-19 12:44:48.813

so First timebreak spent is 10 minutes and second is 4 minutes.
I want to display this record in gridview in same row like that..
VB.NET
StarofDay BreakIn  BreakOut BreakSpent BreakIn  BreakOut BreakSpent OutTime  TimeSpent
12:52PM	  12:03	    12:13   00:10	 12:44    12:48   00:04     4:21PM	03:15

Sub Total	                                                                03:15
Grand Total	                                                                03:15

how can we get this kind output in gridview .

What I have tried:

SQL
CONVERT(varchar(5),ISNULL(DATEADD(minute, DATEDIFF(minute, AttendanceTimeIn, ISNULL(AttendanceTimeOut,SWITCHOFFSET(SYSDATETIMEOFFSET(), ''+05:30''))), 0),0)-
         ISNULL(DATEADD(minute, DATEDIFF(minute, breakTimeIn, ISNULL(breakTimeOut,SWITCHOFFSET(SYSDATETIMEOFFSET(), ''+05:30''))), 0),0)  AS [TimeSpentWork],
DATEDIFF(minute, AttendanceTimeIn, ISNULL(AttendanceTimeOut,SWITCHOFFSET(SYSDATETIMEOFFSET(), ''+05:30'')))-
          ISNULL(DATEDIFF(minute, breakTimeIn, ISNULL(breakTimeOut,SWITCHOFFSET(SYSDATETIMEOFFSET(), ''+05:30''))),0) ) AS [TimeSpentMinutesWork]
Posted
Updated 1-Nov-16 0:27am
Comments
Wendelius 28-Oct-16 10:52am    
What is the common factor for the breaks on a single row? Is it for example theat they are on the same date?

What happens if there is only one break or if there are three breaks or more for the same day? How should these be shown?

1 solution

Select * From ( Select distinct row_number() over(order by "Column Name"
(
Select temp1.Column_Name + ',' AS [text()]
From #TEMP temp1
Where "Condition"
ORDER BY "Column Name"
For XML PATH ('')
) ["Display Name"]
From #TEMP temp2
) [Main]
 
Share this answer
 
v2
Comments
Member 12097108 2-Nov-16 1:28am    
Hey..I am not able to understood this query can you please give me the example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900