1. SQL / Говнокод #2674

    −154.7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    WITH days(num, aday) AS 
    (
    	SELECT 1 AS num, 1 AS aday
    	UNION ALL 
    	SELECT num, aday+1 AS aday FROM days
    	WHERE days.[aday] < DAY( DATEADD(DAY, -DAY(@date), DATEADD(MONTH, 1 , @date)))
    )
    	SELECT     SUM(day1) AS d1, SUM(day2) AS d2, SUM(day3) AS d3, SUM(day4) AS d4, SUM(day5) AS d5, SUM(day6) AS d6, SUM(day7) AS d7, SUM(day8) AS d8, 
    						  SUM(day9) AS d9, SUM(day10) AS d10, SUM(day11) AS d11, SUM(day12) AS d12, SUM(day13) AS d13, SUM(day14) AS d14, SUM(day15) AS d15, 
    						  SUM(day16) AS d16, SUM(day17) AS d17, SUM(day18) AS d18, SUM(day19) AS d19, SUM(day20) AS d20, SUM(day21) AS d21, SUM(day22) AS d22, 
    						  SUM(day23) AS d23, SUM(day24) AS d24, SUM(day25) AS d25, SUM(day26) AS d26, SUM(day27) AS d27, SUM(day28) AS d28, SUM(day29) AS d29, 
    						  SUM(day30) AS d30, SUM(day31) AS d31
    	FROM         (SELECT     CASE aday WHEN 1 THEN 1 ELSE 0 END AS day1, CASE aday WHEN 2 THEN 2 ELSE 0 END AS day2, 
    												  CASE aday WHEN 3 THEN 3 ELSE 0 END AS day3, CASE aday WHEN 4 THEN 4 ELSE 0 END AS day4, 
    												  CASE aday WHEN 5 THEN 5 ELSE 0 END AS day5, CASE aday WHEN 6 THEN 6 ELSE 0 END AS day6, 
    												  CASE aday WHEN 7 THEN 7 ELSE 0 END AS day7, CASE aday WHEN 8 THEN 8 ELSE 0 END AS day8, 
    												  CASE aday WHEN 9 THEN 9 ELSE 0 END AS day9, CASE aday WHEN 10 THEN 10 ELSE 0 END AS day10, 
    												  CASE aday WHEN 11 THEN 11 ELSE 0 END AS day11, CASE aday WHEN 12 THEN 12 ELSE 0 END AS day12, 
    												  CASE aday WHEN 13 THEN 13 ELSE 0 END AS day13, CASE aday WHEN 14 THEN 14 ELSE 0 END AS day14, 
    												  CASE aday WHEN 15 THEN 15 ELSE 0 END AS day15, CASE aday WHEN 16 THEN 16 ELSE 0 END AS day16, 
    												  CASE aday WHEN 17 THEN 17 ELSE 0 END AS day17, CASE aday WHEN 18 THEN 18 ELSE 0 END AS day18, 
    												  CASE aday WHEN 19 THEN 19 ELSE 0 END AS day19, CASE aday WHEN 20 THEN 20 ELSE 0 END AS day20, 
    												  CASE aday WHEN 21 THEN 21 ELSE 0 END AS day21, CASE aday WHEN 22 THEN 22 ELSE 0 END AS day22, 
    												  CASE aday WHEN 23 THEN 23 ELSE 0 END AS day23, CASE aday WHEN 24 THEN 24 ELSE 0 END AS day24, 
    												  CASE aday WHEN 25 THEN 25 ELSE 0 END AS day25, CASE aday WHEN 26 THEN 26 ELSE 0 END AS day26, 
    												  CASE aday WHEN 27 THEN 27 ELSE 0 END AS day27, CASE aday WHEN 28 THEN 28 ELSE 0 END AS day28, 
    												  CASE aday WHEN 29 THEN 29 ELSE 0 END AS day29, CASE aday WHEN 30 THEN 30 ELSE 0 END AS day30, 
    												  CASE aday WHEN 31 THEN 31 ELSE 0 END AS day31
    						   FROM          days) AS col

    Думаю в комментариях не нуждается T_T.

    Запостил: Karasb, 26 Февраля 2010

    Комментарии (0) RSS

    Добавить комментарий

    Ошибка компиляции комментария:
    1. Гости могут высказаться только во вторник, пятницу или субботу
    ava Семь раз отмерь — один отрежь, guest!
    А не использовать ли нам bbcode?
    • [b]жирный[/b] — жирный
    • [i]курсив[/i] — курсив
    • [u]подчеркнутый[/u] — подчеркнутый
    • [s]перечеркнутый[/s] — перечеркнутый
    • [blink]мигающий[/blink] — мигающий
    • [color=red]цвет[/color] — цвет (подробнее)
    • [size=20]размер[/size] — размер (подробнее)
    • [code=<language>]some code[/code] (подробнее)
    Проверочный код