Hello
Sql Server version = 2008
declare @yearmonth varchar(6) set @yearmonth = '202504'
declare @dt1 datetime
declare @dt2 datetime
select @dt1 = dt1 , @dt2 = dt2 from salary_dates d where yearmonth = @yearmonth
--@dt1 = '2025-03-26 and @dt2='2025-04-25
SELECT o.emp_code, e.card_code
FROM populate_overtime o
join employee e on o.emp_code = e.card_code
where (o.dt between @dt1 and @dt2)
The above sql shows 22785 rows i(n table populate_overtime)
Out of 22785 rows (o.emp_code) 7 left (e.left_date)
160355 160273 160421 160422 160431 009838 160268
and 6 joined (e.appoint_date)
160436 160437 160438 160439 160440 160441
I want the result to be left and joined employees.
Result ( 7 +6=13 rows)
card_code =
160355
160273
160421
160422
160431
009838
160268
160436
160437
160438
160439
160440
160441