Hi everyone i am working on some kind of accounting system and encountered some difficulties. the question is already been answered by Abdul Rasheed in this site.
This is the code
declare @sDate datetime,
@eDate datetime
select @sDate = '2013-02-21',
@eDate = '2013-04-25';
with CTE_TEST
as (
select @sDate SDATE,
DATEADD(s, - 1, DATEADD(mm, DATEDIFF(m, 0, @sDate) + 1, 0)) EDATE
union all
select EDATE + 1,
DATEADD(s, - 1, DATEADD(mm, DATEDIFF(m, 0, DATEADD(MONTH, 1, SDATE)) + 1, 0))
from CTE_TEST C
where DATEADD(MONTH, 1, SDATE) < DATEADD(s, - 1, DATEADD(mm, DATEDIFF(m, 0, @eDate) + 1, 0))
)
select DATENAME(MONTH, SDATE) MNAME,
SDATE, (case when EDATE > @eDate then @eDate else EDATE end) EDATE
from CTE_TEST
The code works Great and just like what i want. but i want to insert the result to a new table. How do i do that?