MSSQL creating year buckets from given start and end dates

  Kiến thức lập trình

I have been trying several approaches but I think I need your expertise in this matter. I have a table with several columns, two of those are dates(year-month-day)(start-end) I need to create new columns year buckets, grabbing the year from start date and the year from end date and do a counting. if the year dates are the same the bucket column would have only 1 year.
Here is my desired output. Thank you
enter image description here

LEAVE A COMMENT