I have the following Query
我有以下查询
declare @tempMonth table(ID int IDENTITY(1,1) PRIMARY KEY,Monthid int)
declare @tempDay table(ID int IDENTITY(1,1) PRIMARY KEY,Day int)
declare @AddedDate table(ID int IDENTITY(1,1) PRIMARY KEY,Datee date)
declare @StartEndDate table(ID int IDENTITY(1,1) PRIMARY KEY,StartDate date,Enddate date)
insert into @tempMonth select words Months from dbo.SplitString1('5|8|1|3','|')
insert into @tempDay select words Days from dbo.SplitString1('10|11|12|13','|')
insert into @AddedDate
select convert(varchar,(convert(varchar,Year)+'-'+convert(varchar,Month)+'-'+convert(varchar,Day))) Datee from(
select td.ID,td.Day,tm.Monthid Month, YEAR( getdate()) Year --convert(date,convert(varchar,((Year(getdate()))+'-'+tm.Monthid+'-'+td.Day)))Datee
from @tempDay td
join @tempMonth tm on tm.ID=td.ID
) x
declare @t1 table(ID int IDENTITY(1,1) PRIMARY KEY,StartDate date)
declare @t2 table(ID int IDENTITY(0,1) PRIMARY KEY,StartDate date)
insert into @t1 select Datee StartDate from @AddedDate
insert into @t2 select Datee StartDate from @AddedDate
select t1.ID,t1.StartDate ,
case when t1.ID=4 then DATEADD(day,-1, (SELECT top 1 t3.StartDate FROM @t1 t3 ORDER BY t3.ID)) else
DATEADD(day,-1,t2.StartDate) end EndDate from @t1 t1
left join @t2 t2 on t2.ID=t1.ID
declare @