2013-01-14 ~ 2014-12-31
이란 기간을 입력을 하면
이런 식이 되겠죠...
Select 달, 일 from xxxx where between 2013-01-14 and 2014-12-31
결과값이
2013-01 : 15
2013-02 : 29
2013-03 : 31
2013-04 : 30
....
이런식을 나올 수 있을까요?
Comment 2
-
항해자™
2014.03.12 14:49
;WITH cteTest AS (SELECT CONVERT(datetime,'2013-01-15') AS DY UNION ALLSELECT CONVERT(datetime,'2013-01-25') UNION ALLSELECT CONVERT(datetime,'2013-02-05') UNION ALLSELECT CONVERT(datetime,'2013-02-28') UNION ALLSELECT CONVERT(datetime,'2013-03-13') UNION ALLSELECT CONVERT(datetime,'2013-03-31') UNION ALLSELECT CONVERT(datetime,'2013-04-12') UNION ALLSELECT CONVERT(datetime,'2013-04-30'))SELECT DATEADD(month,DATEDIFF(month,0,DY),0) AS MO, CASE DATEADD(month,DATEDIFF(month,0,DY),0)WHEN '2013-01-01' THEN MIN(DAY(DY))ELSE MAX(DAY(DY))END DYFROM cteTestWHERE DY BETWEEN '2013-01-14' AND '2014-12-31'GROUP BY DATEDIFF(month,0,DY) -
피오니
2014.03.14 13:53
declare @tbl table (seq int);declare @seq int;set @seq = 0;while @seq <= 1000begininsert into @tbl(seq) values(@seq);set @seq = @seq + 1;endselect LEFT(dt, 7) as mon, COUNT(*) as cntfrom (select convert(varchar(10), CAST('2013-01-01' as datetime) + seq, 121) as dtfrom @tbl) xwhere dt between '2013-01-14' and '2014-12-31'group by LEFT(dt, 7)