정확한 명칭이 맞는지 모르겠습니다.
통계 조인을 위해 2년(2007~2008 )정도 년-월-일 (yyyy-mm-dd) 이 들어간 테이블을 만들려고 합니다.
프로시져나 스크립트 있으신분 부탁드립니다.
select dt = yy + '-' + mm + '-' + dd from ( select yy = '2007' union all select yy = '2008' ) a cross join (select mm = right('0' + cast(number as varchar), 2) from master..spt_values where type = 'P' and number between 1 and 12) b
cross join (select dd = right('0' + cast(number as varchar), 2) from master..spt_values where type = 'P' and number between 1 and 31) c
where isdate(yy + '-' + mm + '-' + dd) = 1
select convert(char(10),dateadd(d,number,'2007-01-01'),120) dt
from master..spt_values
where type = 'P'
and number <= datediff(d,'2007-01-01','2008-12-31')
정말 멋진 쿼리네요 ^^ 근데 2000에서는 256개.. 2005에서는 그 원하는 형태 그대로 이네요
-- 2000에서는다음과같이하면될것같네요~
declare @CopyT table (n int primary key)
insert @CopyT
select a.n+b.n+c.n
from (select top 10 str(number,1) n from master..spt_values where type ='P') a,
(select top 10 str(number,1) n from master..spt_values where type ='P') b,
(select top 10 str(number,1) n from master..spt_values where type ='P') c
select convert(char(10),dateadd(d,n,'2007-01-01'),120) dt
from @CopyT
where n <= datediff(d,'2007-01-01','2008-12-31')
감사합니다.. 정말 멋집니다..^^