Home > database >  Ask you a question about Sql Server, online, etc., thank you.
Ask you a question about Sql Server, online, etc., thank you.

Time:09-18

Problem description: there are two records,

EmployeeSalaryGradeID BeginDate EndDate
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2017-01-01 2019-11-30
EA0949F0-25 c8-42 BC - 970 - d - 2019-12-01 BF572258309B NULL

The first BeginDate: 2017-01-01; EndDate: 2019-11-30
Article 2 BeginDate: 2019-12-01; EndDate: NULL (EndDate is NULL, can treat as DateTime maximum value, namely the 9999-12-31,)

Want to effect:
# 1: now I need to according to every year to handle:

For example,
If I want to check the 2016, do not check the record, because the above two records, BeginDate minimum is 2017-01-01,

If I want to check the 2019, so there are 12 records need to be found out,
Respectively is:
EmployeeSalaryGradeID BeginDate EndDate
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-01
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-02
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-03
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-04
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-05
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-06
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-07
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-08
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-09
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-10
10 f8c063 - d7d C3B4-4 - BA0A - DF8125BE5516 2019-11
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B
2019-12

If I want to check the 2020, so there are 12 records need to be found out,
Respectively is:
EmployeeSalaryGradeID BeginDate EndDate
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-01
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-02
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-03
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-04
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-05
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-06
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-07
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-08
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-09
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-10
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-11
EA0949F0-25 c8-42 BC - 970 - d - BF572258309B 2020-12


summary: is the need to select the specific year of record, and then by month break up, how to achieve this effect? Online, etc., grateful!

CodePudding user response:

From the top, top, top,

CodePudding user response:

Don't sink, don't sink, don't sink,

CodePudding user response:

Field segmentation method: https://blog.csdn.net/yenange/article/details/79788877