_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁

Contents

1 旧企?
2 ろ碁一危
3 豌襴 SQL覓
4 CTE vs Cusor(or Loop)


1 旧企? #

れ企 旧 れ螻 螳 螻 .
旧企 螳 企伎朱 旧 蠏蠍郁 谿蠍 危 蟆 襷. 旧 殊 覿豈(莢)願鹸 讌襷, 豺朱 蠍朱 覲 覿豈螳 , 朱朱 螻 螻旧 牛 覲 覿豈企. 旧朱 豌襴伎 朱 語牛覈 伎旧 蠍 煙 .
http://terms.naver.com/item.nhn?dirId=407&docId=808

伎 2005-06-15 殊 蟆 蟆一襯 . 蟆一 2005-08-05手讌襦 . 企 2005-08-05 蟾讌 覿豈襦 讌襷 覩碁Μ 蟆一襯 朱襦 旧 螳 . 企 螳 旧企手 . 襷 れ螻 螳 企 り 螳 覲伎.

   譬襭
--------- --------
20050615  20050805 

蠏碁 蟆郁骸 れ螻 螳 . 蟆一 06 朱, 螳螳06, 07, 08企.

       譬襭       蟆一  
---------- ---------- ---- ----
20050615   20050630   06   06
20050701   20050731   06   07
20050801   20050805   06   08

2 ろ碁一危 #

CREATE TABLE #temp(
        AccountID varchar(20)
,       BeginDT char(8)
,       EndDT char(8)
)

INSERT #temp VALUES('yasicom', '20050615', '20050805')
INSERT #temp VALUES('yangdb', '20050515', '20050605')
INSERT #temp VALUES('endless', '20060101', '20060601')
INSERT #temp VALUES('mkex', '20070513', '20070730')
GO

3 豌襴 SQL覓 #

--貎朱Μ
WITH Dumy(CF)
AS
(
	SELECT 0 CF
	UNION ALL
	SELECT CF + 1 FROM Dumy
	WHERE CF + 1 <= 12     --1豺襷螻壱. 
),
MM(CF)
AS
(
	SELECT CF FROM Dumy
)
SELECT
        AccountID 螻
,	YYYYMM + RIGHT('00' + BeginDD, 2) 
,	YYYYMM + 
		CASE 
			WHEN RIGHT(YYYYMM, 2) <> SUBSTRING(EndDT, 5, 2) THEN RIGHT('00' + EndDD, 2) 
			ELSE RIGHT(EndDT, 2) 
		END 譬襭
,	SUBSTRING(BeginDT, 5, 2) 蟆一
,	RIGHT(YYYYMM, 2) 
FROM 
	(
	SELECT  
		CONVERT(CHAR(6),DATEADD(mm, CF, BeginDT),112) YYYYMM 
	,	CONVERT(VARCHAR(2), 
				   CASE  
						WHEN CF = 0 THEN DATEPART(dd, BeginDT) 
						ELSE 1 
				   END) BeginDD
	,	CONVERT(VARCHAR(2),
					CASE 
						WHEN CONVERT(CHAR(6), EndDT, 112) = 
								CONVERT(CHAR(6), 
									DATEADD(dd,-1, 
										CONVERT(CHAR(6),
											DATEADD(mm,CF + 1, BeginDT),112) + '01'
										),112) 
							THEN DATEPART(dd,EndDT)  
						ELSE DATEPART(dd, 
								DATEADD(dd, -1, 
									CONVERT(CHAR(6),DATEADD(mm,CF + 1, BeginDT), 112)+'01')) 
					END) EndDD
	,	BeginDT
	,	EndDT
	,	AccountID
	FROM #temp A CROSS JOIN (SELECT CF FROM MM) B
	WHERE CF <= DATEDIFF(mm, BeginDT, EndDT) 
	) T
ORDER BY 螻, 

4 CTE vs Cusor(or Loop) #

れ URL CTE 焔レ ろ碁ゼ 讌 蟆 襴 蟆企.
蠏碁襷 覺 蟆讌襷, Loop襯 伎 蠏貎朱Μ 襭 焔レ 譬 蟆 . 覓語 蠏貎朱Μ襯 伎 襭 る 蟆 谿瑚手 襷 蟆企, 焔 ろ碁 螳 企慨 蟆 譬 ..
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

語 襷 螳螻 碁 覿襯企伎 苦 襷螳. (危襴 )