_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › 蠏貎朱Μ襯殊伎Dumy企襷り鍵

Contents

1 Hello World
2 1覿10蟾讌
3 20000101~ 20001231手讌襷り鍵
4
5 覓語(螳襦) -> 覓語(碁)
6 譯朱朱7襴襦 企 襷り鍵


1 Hello World #

 cpp
#include <stdio.h>
int main()
{
        printf("Hello World!!\n");
        return 0;
}

2 1覿10蟾讌 #

WITH Dumy(Seq)
AS
(
        SELECT 0 Seq
        UNION ALL
        SELECT Seq + 1 FROM Dumy
        WHERE Seq + 1 <= 10
)
SELECT Seq FROM Dumy
OPTION (MAXRECURSION 0);
--蠏螳 100 豐螻狩 蟆曙磯 OPTION (MAXRECURSION 0)襯 覿譴 .

with dumy
as
(
        select convert(binary(1), 0x01) bin
        union all
        select convert(binary(1), bin + 1) from dumy
        where bin + 1 <= 0xff
)
select bin, convert(tinyint, bin) num from dumy
option (maxrecursion 0);

3 20000101~ 20001231手讌襷り鍵 #

WITH temp(DT)
AS
(
        SELECT CONVERT(datetime, '20000101') DT 
        UNION ALL
        SELECT DT + 1 FROM temp
        WHERE DT + 1 < '20010101'
)
SELECT DT FROM temp
OPTION (MAXRECURSION 0);
--蠏螳 100 豐螻狩 蟆曙磯 OPTION (MAXRECURSION 0)襯 覿譴 .

4 #

--螳 覃伎  j 矩り 譟磯 蠏谿蟆伎 襷蟇磯.. <;
DECLARE @DT datetime;
SET @DT = GETDATE();

WITH temp(DT)
AS
(
        SELECT DATEADD(mm, -2, @DT) DT 
        UNION ALL
        SELECT DT + 1 FROM temp
        WHERE DT + 1 < DATEADD(mm, 2, @DT)
)
SELECT
	MIN(YY) YY
,	MIN(MM) MM
,	ISNULL(MIN(CASE WHEN WD = 1 THEN DD END), '') 
,	ISNULL(MIN(CASE WHEN WD = 2 THEN DD END), '') 
,	ISNULL(MIN(CASE WHEN WD = 3 THEN DD END), '') 
,	ISNULL(MIN(CASE WHEN WD = 4 THEN DD END), '') 
,	ISNULL(MIN(CASE WHEN WD = 5 THEN DD END), '') 覈
,	ISNULL(MIN(CASE WHEN WD = 6 THEN DD END), '') 蠍
,	ISNULL(MIN(CASE WHEN WD = 7 THEN DD END), '') 
FROM (
	SELECT 
		DT 
	,	CONVERT(varchar, DATEPART(dd, DT)) DD
	,	DATEPART(mm, DT) MM
	,	DATEPART(yy, DT) YY
	,	DATEPART(weekday, DT) WD
	,	DATEPART(ww, DT) WW
	FROM temp
	WHERE DATEPART(mm, DT) = DATEPART(mm, @DT) 
--		IN 
--		(
--			DATEPART(mm, DATEADD(mm, -1, GETDATE()))
--		,	DATEPART(mm, DATEADD(mm, 1, GETDATE()))
--		,	DATEPART(mm, DATEADD(mm, 0, GETDATE()))
--		)
) T
GROUP BY
	WW, MM
ORDER BY 1, 2
OPTION (MAXRECURSION 0); 

5 覓語(螳襦) -> 覓語(碁) #

 Sql
Declare
	@Str VarChar(max);
Select
	@Str='This is a test...';

With Parse as
(
	Select
		SubString(@Str,1,1)[Chr],
		1[Idx]
	Union All
	Select
		SubString(@Str,Idx+1,1),
		Idx+1
	from Parse
	where (Idx+1)<=Len(@Str)
)
Select
	*
from Parse
option (MaxRecursion 0);

6 譯朱朱7襴襦 企 襷り鍵 #

 Sql
WITH temp(DT)
AS
(
        SELECT CONVERT(datetime, '18000101') DT 
        UNION ALL
        SELECT DT + 1 FROM temp
        WHERE DT + 1 < CONVERT(char(8), GETDATE(), 112)
)
SELECT
	DT
,	Birth7
,	CASE WHEN Age < 0 THEN 0 ELSE Age END -
	CASE WHEN SUBSTRING(Birth7, 3, 4) >= SUBSTRING(CONVERT(char(8), GETDATE(), 112), 5, 4) THEN 1 ELSE 0 END Age
FROM (
	SELECT 
		DT
	,	CASE 
			WHEN DT >= '20000101' THEN RIGHT(CONVERT(char(8), DT, 112), 6) + CONVERT(char(1), T.Gender + 2)
			WHEN DT <  '19000101' THEN RIGHT(CONVERT(char(8), DT, 112), 6) + CONVERT(char(1), RIGHT(T.Gender + 8, 1))
			ELSE RIGHT(CONVERT(char(8), DT, 112), 6) + CONVERT(char(1), T.Gender + 0)
		END Birth7
	,	DATEDIFF(yy, DT, CONVERT(char(8), GETDATE()-1, 112)) Age
	FROM temp
		CROSS JOIN (SELECT 1 Gender UNION ALL SELECT 2) T
) T
OPTION (MAXRECURSION 0);
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

Youth is not a time of life but it is a state of mind. (覓伎碁)