database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
ㆍMS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MS-SQL Q&A 4088 게시물 읽기
No. 4088
딕셔너리(?)테이블 생성
작성자
작성일
2008-03-03 18:35
조회수
4,087

정확한 명칭이 맞는지 모르겠습니다.


통계 조인을 위해 2년(2007~2008 )정도  년-월-일 (yyyy-mm-dd)  이 들어간 테이블을 만들려고 합니다.


프로시져나 스크립트 있으신분 부탁드립니다.

이 글에 대한 댓글이 총 5건 있습니다.

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

.님이 2008-03-03 20:20에 작성한 댓글입니다. Edit

 

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')

최석준(beatchoi)님이 2008-03-03 21:10에 작성한 댓글입니다.

정말 멋진 쿼리네요 ^^
근데 2000에서는 256개.. 
2005에서는 그 원하는 형태 그대로 이네요

.님이 2008-03-04 10:06에 작성한 댓글입니다.
이 댓글은 2008-03-04 10:10에 마지막으로 수정되었습니다. Edit

 

-- 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')

최석준(beatchoi)님이 2008-03-04 10:28에 작성한 댓글입니다.

감사합니다..   정말 멋집니다..^^

군님이 2008-03-05 08:33에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
4095[문외한] Window Server2003에서 사용하는 데이터 베이스 프로그램속도 저하
신현근
2008-03-06
3669
4091프로시져 에서 like 문의 드립니다. [4]
궁금이
2008-03-04
4081
4090DB 쿼리 문의 드립니다.
허문갑
2008-03-04
3804
4088딕셔너리(?)테이블 생성 [5]
2008-03-03
4087
4087유저별로 데이타베이스 분리 [1]
김정훈
2008-03-03
3799
4086컬럼 정보를 가져오는 쿼리 맞는지 확인좀 부탁드려요
라스트파스칼
2008-03-02
4014
4085세로 데이터를 가로 테이블로 통계내려고 하는데요 [1]
장병주
2008-02-29
5233
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다