Regarding NIGHT SHIFT EmployeesParent-Child Tree Hierarchical ORDERHow can I “shift” certain column...
Is it acceptable for a professor to tell male students to not think that they are smarter than female students?
How seriously should I take size and weight limits of hand luggage?
Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?
Why didn't Boeing produce its own regional jet?
What does the expression "A Mann!" means
Reverse dictionary where values are lists
How much of data wrangling is a data scientist's job?
Should I tell management that I intend to leave due to bad software development practices?
Are there any examples of a variable being normally distributed that is *not* due to the Central Limit Theorem?
Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?
What killed these X2 caps?
Is it logically or scientifically possible to artificially send energy to the body?
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
How can saying a song's name be a copyright violation?
How did the Super Star Destroyer Executor get destroyed exactly?
Size of subfigure fitting its content (tikzpicture)
Ambiguity in the definition of entropy
A category-like structure without composition?
How can I determine if the org that I'm currently connected to is a scratch org?
Alternative to sending password over mail?
All in one piece, we mend holes in your socks
Should I cover my bicycle overnight while bikepacking?
Why are the 737's rear doors unusable in a water landing?
Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?
Regarding NIGHT SHIFT Employees
Parent-Child Tree Hierarchical ORDERHow can I “shift” certain column values to different rows in an existing table?24x7 vs Night Time WindowAbout employee who come out at nightFirst-In and Last-Out times for Night Shift EmployeesSplit Date/Time value for Night Shift EmployeeLSN numbers query regarding Differential backupsFind the second highest salary of employeesEmployee Shift Check - Nested CursorHow to get Current Shift?
I have small issue on night shit of our employees .. Shift timings are from 22:00 to 6:00 Am .. If the shift starts today at 11 Pm it will end the next morning at 6:00 Am (7 Hours ). Here I want to know the first Swipe in and First last Swipe out.. Below here am providing the table structure and some sample data along with the expected output ....I need a procedure with inputs like @loginname, @startdate, @Enddate
CREATE TABLE [dbo].[CardData](
[CardDataID] [bigint] NOT NULL,
[DataMovementHistoryID] [bigint] NULL,
[LoginName] varchar NULL,
[ShiftID] [int] NULL,
[CardTime] [datetime] NOT NULL,
[IsInOrOut] [bit] NULL,
[IsProcessed] [bit] NULL
) ON [PRIMARY]
--TestCase 1--
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11290, 2200, 'B1000', 1, CAST(N'2019-06-01 9:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11291, 2200, 'B1000', 1, CAST(N'2019-06-01 12:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11292, 2200, 'B1000', 1, CAST(N'2019-06-01 15:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11293, 2200, 'B1000', 1, CAST(N'2019-06-01 17:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11294, 2200, 'B1000', 1, CAST(N'2019-06-02 10:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-02 13:55:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-02 14:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-02 16:01:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-03 08:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-03 13:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-03 15:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11298, 2200, 'B1000', 1, CAST(N'2019-06-03 17:01:00.000' AS DateTime), 1, 1)
---@loginname='B1000'
---@startdate='2019-06-01'
---@Enddate='2019-06-15'
loginname , DT , FirstIn , InFlag , LastOut , OutFlag
B1000 , 2019-06-02 ,2019-06-02 10:24:00, 0 , 2019-06-02 16:01:00, 0
B1000 , 2019-06-03, 2019-06-03 8:24:00 ,1 , 2019-06-03 17:01:00 ,1
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11299, 2200, 'C2000', 8, CAST(N'2019-07-01 23:05:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11300, 2200, 'C2000', 8, CAST(N'2019-07-02 00:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11301, 2200, 'C2000', 8, CAST(N'2019-07-02 3:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11302, 2200, 'C2000', 8, CAST(N'2019-07-02 5:05:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11303, 2200, 'C2000', 8, CAST(N'2019-07-03 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11304, 2200, 'C2000', 8, CAST(N'2019-07-04 02:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11305, 2200, 'C2000', 8, CAST(N'2019-07-04 4:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11306, 2200, 'C2000', 8, CAST(N'2019-07-04 05:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11307, 2200, 'C2000', 8, CAST(N'2019-07-05 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11308, 2200, 'C2000', 8, CAST(N'2019-07-06 02:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11309, 2200, 'C2000', 8, CAST(N'2019-07-06 04:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11310, 2200, 'C2000', 8, CAST(N'2019-07-06 05:57:00.000' AS DateTime), 1, 1)
---@loginname='C2000'
---@startdate='2019-07-01'
---@Enddate='2019-07-15'
--Required output
loginname, DT, FIrstIN, InFLag, Lastout, Outflag
C2000, 2019-07-01, 2019-07-01 23:05:00, 0, 2019-07-01 5:05:00, 1
C2000, 2019-07-05, 2019-07-05 23:24:00, 1, 2019-07-05 05:57:00.000, 1
sql-server sql-server-2012 stored-procedures
add a comment |
I have small issue on night shit of our employees .. Shift timings are from 22:00 to 6:00 Am .. If the shift starts today at 11 Pm it will end the next morning at 6:00 Am (7 Hours ). Here I want to know the first Swipe in and First last Swipe out.. Below here am providing the table structure and some sample data along with the expected output ....I need a procedure with inputs like @loginname, @startdate, @Enddate
CREATE TABLE [dbo].[CardData](
[CardDataID] [bigint] NOT NULL,
[DataMovementHistoryID] [bigint] NULL,
[LoginName] varchar NULL,
[ShiftID] [int] NULL,
[CardTime] [datetime] NOT NULL,
[IsInOrOut] [bit] NULL,
[IsProcessed] [bit] NULL
) ON [PRIMARY]
--TestCase 1--
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11290, 2200, 'B1000', 1, CAST(N'2019-06-01 9:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11291, 2200, 'B1000', 1, CAST(N'2019-06-01 12:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11292, 2200, 'B1000', 1, CAST(N'2019-06-01 15:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11293, 2200, 'B1000', 1, CAST(N'2019-06-01 17:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11294, 2200, 'B1000', 1, CAST(N'2019-06-02 10:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-02 13:55:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-02 14:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-02 16:01:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-03 08:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-03 13:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-03 15:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11298, 2200, 'B1000', 1, CAST(N'2019-06-03 17:01:00.000' AS DateTime), 1, 1)
---@loginname='B1000'
---@startdate='2019-06-01'
---@Enddate='2019-06-15'
loginname , DT , FirstIn , InFlag , LastOut , OutFlag
B1000 , 2019-06-02 ,2019-06-02 10:24:00, 0 , 2019-06-02 16:01:00, 0
B1000 , 2019-06-03, 2019-06-03 8:24:00 ,1 , 2019-06-03 17:01:00 ,1
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11299, 2200, 'C2000', 8, CAST(N'2019-07-01 23:05:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11300, 2200, 'C2000', 8, CAST(N'2019-07-02 00:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11301, 2200, 'C2000', 8, CAST(N'2019-07-02 3:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11302, 2200, 'C2000', 8, CAST(N'2019-07-02 5:05:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11303, 2200, 'C2000', 8, CAST(N'2019-07-03 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11304, 2200, 'C2000', 8, CAST(N'2019-07-04 02:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11305, 2200, 'C2000', 8, CAST(N'2019-07-04 4:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11306, 2200, 'C2000', 8, CAST(N'2019-07-04 05:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11307, 2200, 'C2000', 8, CAST(N'2019-07-05 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11308, 2200, 'C2000', 8, CAST(N'2019-07-06 02:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11309, 2200, 'C2000', 8, CAST(N'2019-07-06 04:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11310, 2200, 'C2000', 8, CAST(N'2019-07-06 05:57:00.000' AS DateTime), 1, 1)
---@loginname='C2000'
---@startdate='2019-07-01'
---@Enddate='2019-07-15'
--Required output
loginname, DT, FIrstIN, InFLag, Lastout, Outflag
C2000, 2019-07-01, 2019-07-01 23:05:00, 0, 2019-07-01 5:05:00, 1
C2000, 2019-07-05, 2019-07-05 23:24:00, 1, 2019-07-05 05:57:00.000, 1
sql-server sql-server-2012 stored-procedures
add a comment |
I have small issue on night shit of our employees .. Shift timings are from 22:00 to 6:00 Am .. If the shift starts today at 11 Pm it will end the next morning at 6:00 Am (7 Hours ). Here I want to know the first Swipe in and First last Swipe out.. Below here am providing the table structure and some sample data along with the expected output ....I need a procedure with inputs like @loginname, @startdate, @Enddate
CREATE TABLE [dbo].[CardData](
[CardDataID] [bigint] NOT NULL,
[DataMovementHistoryID] [bigint] NULL,
[LoginName] varchar NULL,
[ShiftID] [int] NULL,
[CardTime] [datetime] NOT NULL,
[IsInOrOut] [bit] NULL,
[IsProcessed] [bit] NULL
) ON [PRIMARY]
--TestCase 1--
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11290, 2200, 'B1000', 1, CAST(N'2019-06-01 9:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11291, 2200, 'B1000', 1, CAST(N'2019-06-01 12:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11292, 2200, 'B1000', 1, CAST(N'2019-06-01 15:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11293, 2200, 'B1000', 1, CAST(N'2019-06-01 17:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11294, 2200, 'B1000', 1, CAST(N'2019-06-02 10:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-02 13:55:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-02 14:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-02 16:01:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-03 08:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-03 13:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-03 15:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11298, 2200, 'B1000', 1, CAST(N'2019-06-03 17:01:00.000' AS DateTime), 1, 1)
---@loginname='B1000'
---@startdate='2019-06-01'
---@Enddate='2019-06-15'
loginname , DT , FirstIn , InFlag , LastOut , OutFlag
B1000 , 2019-06-02 ,2019-06-02 10:24:00, 0 , 2019-06-02 16:01:00, 0
B1000 , 2019-06-03, 2019-06-03 8:24:00 ,1 , 2019-06-03 17:01:00 ,1
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11299, 2200, 'C2000', 8, CAST(N'2019-07-01 23:05:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11300, 2200, 'C2000', 8, CAST(N'2019-07-02 00:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11301, 2200, 'C2000', 8, CAST(N'2019-07-02 3:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11302, 2200, 'C2000', 8, CAST(N'2019-07-02 5:05:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11303, 2200, 'C2000', 8, CAST(N'2019-07-03 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11304, 2200, 'C2000', 8, CAST(N'2019-07-04 02:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11305, 2200, 'C2000', 8, CAST(N'2019-07-04 4:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11306, 2200, 'C2000', 8, CAST(N'2019-07-04 05:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11307, 2200, 'C2000', 8, CAST(N'2019-07-05 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11308, 2200, 'C2000', 8, CAST(N'2019-07-06 02:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11309, 2200, 'C2000', 8, CAST(N'2019-07-06 04:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11310, 2200, 'C2000', 8, CAST(N'2019-07-06 05:57:00.000' AS DateTime), 1, 1)
---@loginname='C2000'
---@startdate='2019-07-01'
---@Enddate='2019-07-15'
--Required output
loginname, DT, FIrstIN, InFLag, Lastout, Outflag
C2000, 2019-07-01, 2019-07-01 23:05:00, 0, 2019-07-01 5:05:00, 1
C2000, 2019-07-05, 2019-07-05 23:24:00, 1, 2019-07-05 05:57:00.000, 1
sql-server sql-server-2012 stored-procedures
I have small issue on night shit of our employees .. Shift timings are from 22:00 to 6:00 Am .. If the shift starts today at 11 Pm it will end the next morning at 6:00 Am (7 Hours ). Here I want to know the first Swipe in and First last Swipe out.. Below here am providing the table structure and some sample data along with the expected output ....I need a procedure with inputs like @loginname, @startdate, @Enddate
CREATE TABLE [dbo].[CardData](
[CardDataID] [bigint] NOT NULL,
[DataMovementHistoryID] [bigint] NULL,
[LoginName] varchar NULL,
[ShiftID] [int] NULL,
[CardTime] [datetime] NOT NULL,
[IsInOrOut] [bit] NULL,
[IsProcessed] [bit] NULL
) ON [PRIMARY]
--TestCase 1--
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11290, 2200, 'B1000', 1, CAST(N'2019-06-01 9:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11291, 2200, 'B1000', 1, CAST(N'2019-06-01 12:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11292, 2200, 'B1000', 1, CAST(N'2019-06-01 15:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11293, 2200, 'B1000', 1, CAST(N'2019-06-01 17:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11294, 2200, 'B1000', 1, CAST(N'2019-06-02 10:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-02 13:55:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-02 14:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-02 16:01:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11295, 2200, 'B1000', 1, CAST(N'2019-06-03 08:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11296, 2200, 'B1000', 1, CAST(N'2019-06-03 13:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11297, 2200, 'B1000', 1, CAST(N'2019-06-03 15:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11298, 2200, 'B1000', 1, CAST(N'2019-06-03 17:01:00.000' AS DateTime), 1, 1)
---@loginname='B1000'
---@startdate='2019-06-01'
---@Enddate='2019-06-15'
loginname , DT , FirstIn , InFlag , LastOut , OutFlag
B1000 , 2019-06-02 ,2019-06-02 10:24:00, 0 , 2019-06-02 16:01:00, 0
B1000 , 2019-06-03, 2019-06-03 8:24:00 ,1 , 2019-06-03 17:01:00 ,1
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11299, 2200, 'C2000', 8, CAST(N'2019-07-01 23:05:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11300, 2200, 'C2000', 8, CAST(N'2019-07-02 00:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11301, 2200, 'C2000', 8, CAST(N'2019-07-02 3:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11302, 2200, 'C2000', 8, CAST(N'2019-07-02 5:05:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11303, 2200, 'C2000', 8, CAST(N'2019-07-03 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11304, 2200, 'C2000', 8, CAST(N'2019-07-04 02:55:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11305, 2200, 'C2000', 8, CAST(N'2019-07-04 4:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11306, 2200, 'C2000', 8, CAST(N'2019-07-04 05:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11307, 2200, 'C2000', 8, CAST(N'2019-07-05 23:24:00.000' AS DateTime), 1, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11308, 2200, 'C2000', 8, CAST(N'2019-07-06 02:57:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11309, 2200, 'C2000', 8, CAST(N'2019-07-06 04:24:00.000' AS DateTime), 0, 1)
INSERT INTO [dbo].[CardData] ([CardDataID], [DataMovementHistoryID], [LoginName], [ShiftID], [CardTime], [IsInOrOut], [IsProcessed]) VALUES (11310, 2200, 'C2000', 8, CAST(N'2019-07-06 05:57:00.000' AS DateTime), 1, 1)
---@loginname='C2000'
---@startdate='2019-07-01'
---@Enddate='2019-07-15'
--Required output
loginname, DT, FIrstIN, InFLag, Lastout, Outflag
C2000, 2019-07-01, 2019-07-01 23:05:00, 0, 2019-07-01 5:05:00, 1
C2000, 2019-07-05, 2019-07-05 23:24:00, 1, 2019-07-05 05:57:00.000, 1
sql-server sql-server-2012 stored-procedures
sql-server sql-server-2012 stored-procedures
asked 1 min ago
AdityaAditya
1
1
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f233905%2fregarding-night-shift-employees%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f233905%2fregarding-night-shift-employees%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown