I have a two table with the below sample output. tb1 is in time and tb2 is out time
I want to build a query to achieve the below results with null values if row in tb2 not in tb2 or row in tb1 not in tb1:
i need get null if OINDX in table2 and not in table1 or IINDX in table1 and not in table2 and if date not in dates between two date get null row with date only like this photo
this code to create two tables to try code and help me
CREATE TABLE [dbo].[TIMEIN](
[IINDX] [int] NULL,
[USERID] [int] NULL,
[Date] [date] NULL,
[CHECKTIME] [datetime] NULL,
[CHECKTYPE] [varchar](1) NULL
) ON [PRIMARY]
INSERT [dbo].[TIMEIN] VALUES (1, 60, CAST(N'2018-02-07' AS Date), CAST(N'2018-02-07T06:58:48.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (3, 60, CAST(N'2018-02-08' AS Date), CAST(N'2018-02-08T06:01:09.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (6, 60, CAST(N'2018-02-09' AS Date), CAST(N'2018-02-09T06:57:43.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (8, 60, CAST(N'2018-02-10' AS Date), CAST(N'2018-02-10T06:34:28.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (10, 60, CAST(N'2018-02-11' AS Date), CAST(N'2018-02-11T05:59:38.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (12, 60, CAST(N'2018-02-12' AS Date), CAST(N'2018-02-12T06:02:14.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (14, 60, CAST(N'2018-02-13' AS Date), CAST(N'2018-02-13T06:00:25.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (16, 60, CAST(N'2018-02-14' AS Date), CAST(N'2018-02-14T06:01:59.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (18, 60, CAST(N'2018-02-15' AS Date), CAST(N'2018-02-15T06:01:56.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (20, 60, CAST(N'2018-02-22' AS Date), CAST(N'2018-02-22T13:58:31.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (22, 60, CAST(N'2018-02-23' AS Date), CAST(N'2018-02-23T18:57:01.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (24, 60, CAST(N'2018-02-24' AS Date), CAST(N'2018-02-24T21:54:01.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (26, 60, CAST(N'2018-02-25' AS Date), CAST(N'2018-02-25T21:53:58.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (28, 60, CAST(N'2018-02-26' AS Date), CAST(N'2018-02-26T22:03:14.000' AS DateTime), N'I')
INSERT [dbo].[TIMEIN] VALUES (30, 60, CAST(N'2018-02-27' AS Date), CAST(N'2018-02-27T21:57:51.000' AS DateTime), N'I')
CREATE TABLE [dbo].[TIMEOUT](
[OINDX] [int] NULL,
[USERID] [int] NULL,
[Date] [date] NULL,
[CHECKTIME] [datetime] NULL,
[CHECKTYPE] [varchar](1) NULL
) ON [PRIMARY]
INSERT [dbo].[TIMEOUT] VALUES (1, 60, CAST(N'2018-02-07' AS Date), CAST(N'2018-02-07T15:59:32.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (3, 60, CAST(N'2018-02-08' AS Date), CAST(N'2018-02-08T15:00:32.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (4, 60, CAST(N'2018-02-08' AS Date), CAST(N'2018-02-08T15:00:34.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (6, 60, CAST(N'2018-02-09' AS Date), CAST(N'2018-02-09T19:00:03.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (8, 60, CAST(N'2018-02-10' AS Date), CAST(N'2018-02-10T15:31:16.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (10, 60, CAST(N'2018-02-11' AS Date), CAST(N'2018-02-11T15:01:47.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (12, 60, CAST(N'2018-02-12' AS Date), CAST(N'2018-02-12T15:03:06.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (14, 60, CAST(N'2018-02-13' AS Date), CAST(N'2018-02-13T15:01:40.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (16, 60, CAST(N'2018-02-14' AS Date), CAST(N'2018-02-14T15:00:34.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (18, 60, CAST(N'2018-02-15' AS Date), CAST(N'2018-02-15T15:02:55.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (20, 60, CAST(N'2018-02-22' AS Date), CAST(N'2018-02-22T22:20:42.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (22, 60, CAST(N'2018-02-24' AS Date), CAST(N'2018-02-24T06:03:39.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (24, 60, CAST(N'2018-02-25' AS Date), CAST(N'2018-02-25T07:04:37.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (26, 60, CAST(N'2018-02-26' AS Date), CAST(N'2018-02-26T07:00:16.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (28, 60, CAST(N'2018-02-27' AS Date), CAST(N'2018-02-27T07:04:08.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (30, 60, CAST(N'2018-02-27' AS Date), CAST(N'2018-02-27T21:58:48.000' AS DateTime), N'O')
INSERT [dbo].[TIMEOUT] VALUES (31, 60, CAST(N'2018-02-28' AS Date), CAST(N'2018-02-28T07:00:18.000' AS DateTime), N'O')
i use this code to get list dates between two datw
DECLARE @Date1 DATE = '2018-02-07'; DECLARE @Date2 DATE = '2018-02-28';
SELECT DATEADD(DAY,number,@Date1) [Date] FROM master..spt_values
WHERE type = 'P' AND DATEADD(DAY,number,@Date1) <= @Date2