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

    −168

    1. 1
    decode(coalesce(d.modif19,'0'),'0','0',d.modif19)

    siv163, 19 Июня 2014

    Комментарии (12)
  2. SQL / Говнокод #16105

    −165

    1. 1
    http://pastebin.com/YSWwKmGb

    Кроме как линком не влезает. Но оно того стоит...

    kostoprav, 03 Июня 2014

    Комментарии (35)
  3. SQL / Говнокод #16099

    −169

    1. 1
    SELECT Status_ID FROM User,UserStatus,Status WHERE User_ID=UserStatus_UserID AND UserStatus_StatusID=Status_ID GROUP BY Status_ID

    dafuq, 03 Июня 2014

    Комментарии (2)
  4. SQL / Говнокод #16070

    −167

    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
    30. 30
    31. 31
    32. 32
    insert into #rez
     select  ('<html>')
      Union all
     select  ('<head>')
      Union all
     select  ('<meta http-equiv="content-type" content="text/html; charset=Windows-1251">')
      Union all
     select  ('<title> Report </title>')
      Union all
     select  ('<style type="text/css">')
      Union all
     select  ('.{font-family:Arial;font-size:7pt;}')
      Union all
     select  ('#top{border-top-style:solid;border-width:1;}')
      Union all
     select  ('.titl{font-size:15px;}')
      Union all
     select  ('.title{background-color:rgb(240,240,240)}')
      Union all
     select  ('.data{background-color:rgb(248,248,248)}')
      Union all
     select  ('.nam{background-color:rgb(245,245,245)}')
      Union all
     select  ('</style>')
      union all
     select  ('</head>')
      union all
     select  ('<body>')
     UNION ALL
     select  '<P align=left><SPAN style="FONT-SIZE: 12pt">' + @var1 + '<br><br>'
      union all
    -- ... и еще килобайт 50 подобной фигни. местами с генерацией табличек, с помощью if/case подсвеченных ячеек.

    Спорите FastCGI vs WSGI? Говорите "Логика отдельно, шаблончики отдельно", ORM? Ну-ну. добро пожаловать в Махровый ентепрайз.

    bliznezz, 28 Мая 2014

    Комментарии (7)
  5. SQL / Говнокод #16052

    −114

    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
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    select 
    
    row_number() over (order by count(*) desc) r, 
    
    case when t719.f7171 is null and t719.f7201 is null then 'За поданням
    голови ОВК, капітана судна, керівн. полярної станції України' 
    
                when t719.f7171 is not null  then t717.name1 
    
                when t719.f7201 is not null  then t720.f7202||'
    '||t720.f7203||' '||t720.f7204
    
           end t021f02, 
    
            count(*) count1
    
    from  t719,
    
          t066,
    
          t714,
    
          v1_t717 t717,
    
          t720
    
    where t719.t001f01=PT001F01 and
    
          t719.t001f01=t066.t001f01 and
    
          t719.f7331=t066.f7331 and
    
          t719.f7141=t066.f7141 and
    
          t719.f7191=t066.f7191 and
    
          t066.T066F02 is not null and
    
          t066.T066F03 is null and
    
          t719.t001f01=t714.t001f01 and
    
          t719.f7331=t714.f7331 and
    
          t719.f7141=t714.f7141 and
    
          t714.f71480 is null and
    
          t719.f7171=t717.f7171(+) and
    
          t719.t001f01=t717.t001f01(+) and
    
          t719.f7201=t720.f7201(+) and
    
          t719.t001f01=t720.t001f01(+)
    
    group by case when t719.f7171 is null and t719.f7201 is null then 'За
    поданням голови ОВК, капітана судна, керівн. полярної станції України' 
    
                  when t719.f7171 is not null  then t717.name1 
    
                  when t719.f7201 is not null  then t720.f7202||'
    '||t720.f7203||' '||t720.f7204
    
             end
    
    order by count(*) desc, 1;

    Оттуда же.

    Ну и как такое можно сапортить?

    DBdev, 24 Мая 2014

    Комментарии (7)
  6. SQL / Говнокод #15902

    −118

    1. 1
    2. 2
    3. 3
    RAISERROR ('Transaction (Process ID 53) was deadlocked on lock resources with another process 
    and has been chosen as the deadlock victim. Rerun thetransaction', 16, 1 );
    RETURN;

    гыгыгы

    bahamot, 05 Мая 2014

    Комментарии (3)
  7. SQL / Говнокод #15698

    −123

    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
    30. 30
    31. 31
    32. 32
    33. 33
    ALTER TRIGGER [dbo].[ObjectTrade]
    ON [dbo].[packets] 
    AFTER INSERT
    AS 
    BEGIN
    SET NOCOUNT ON;
    
    DECLARE
    @id_key int,
    @id_th int,
    @date_end datetime,
    @date_beg datetime
    
    SET @id_key = (SELECT id_key FROM inserted)
    SET @id_th = (SELECT id_th FROM inserted WHERE id_key = @id_key)
    SET @date_end = (SELECT date_end FROM inserted WHERE id_key = @id_key)
    SET @date_beg = (SELECT date_beg FROM inserted WHERE id_key = @id_key)
    
    IF @id_th = 183 
    UPDATE packets 
    SET packets.date_end = CAST('12-05-2014' AS DATE) 
    WHERE id_key =@id_key
    
    IF (CAST(@date_end AS DATE) BETWEEN '08-03-2014' and '10-03-2014') SET @date_end = '07-03-2014'
    IF (CAST(@date_end AS DATE) BETWEEN '01-05-2014' and '04-05-2014') SET @date_end = '30-04-2014'
    IF (CAST(@date_end AS DATE) BETWEEN '09-05-2014' and '11-05-2014') SET @date_end = '08-05-2014'
    IF (CAST(@date_end AS DATE) BETWEEN '12-06-2014' and '15-06-2014') SET @date_end = '11-06-2014'
    IF (CAST(@date_end AS DATE) BETWEEN '02-11-2014' and '04-11-2014') SET @date_end = '01-11-2014'
    IF (CAST(@date_end AS DATE) BETWEEN '01-01-2015' and '08-01-2015') SET @date_end = '31-12-2014'
    IF DATEPART(WEEKDAY, @date_end) = 7 SET @date_end = DATEADD(DAY, -1, @date_end)
    UPDATE packets SET packets.date_end = @date_end WHERE id_key =@id_key
    
    END

    kerberos, 07 Апреля 2014

    Комментарии (20)
  8. SQL / Говнокод #15646

    −123

    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
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    select ...
    case 
     -- периоды пересекаются только в одной точке (2)
    when (vw.hEndDate=vw.rStartDate) 
    then vw.hEndDate
    when (vw.rEndDate=vw.hStartDate) 
    then vw.rEndDate
    -- периоды пересекаются в определенной области (2)
    when (vw.hStartDate > vw.rstartdate and IsNull(vw.hEndDate,'01-01-2099')<IsNull(vw.rEndDate,'01-01-2099')) then vw.hStartDate
    when ((vw.rStartDate between vw.hStartDate and vw.hEndDate) and (vw.hEndDate between vw.rStartDate and vw.rEndDate)) 
    then vw.rStartDate
    when ((vw.hStartDate between vw.rStartDate and vw.rEndDate) and (vw.rEndDate between vw.hStartDate and vw.hEndDate)) 
    then vw.hStartDate
    -- периоды полностью совпадают (1)
    when (vw.hStartDate=vw.rStartDate and vw.hEndDate=vw.rEndDate) 
    then vw.hStartDate
    -- периоды совпадают в одной точке и перекрываются (4)
    when (vw.hStartDate=vw.rStartDate and vw.rEndDate<vw.hEndDate) 
    then vw.hStartDate
    when (vw.hStartDate=vw.rStartDate and vw.hEndDate<vw.rEndDate) 
    then vw.hStartDate
    when (vw.hEndDate=vw.rEndDate and vw.rStartDate>vw.hStartDate) 
    then vw.rStartDate
    when (vw.hEndDate=vw.rEndDate and vw.rStartDate<vw.hStartDate) 
    then vw.hStartDate
    end as MainStartDate  
    ,case 
    -- периоды пересекаются только в одной точке (2)
    when (vw.hEndDate=vw.rStartDate) 
    then vw.hEndDate
    when (vw.rEndDate=vw.hStartDate) 
    then vw.rEndDate
    -- периоды пересекаются в определенной области (2)
    when (vw.hStartDate > vw.rstartdate and IsNull(vw.hEndDate,'01-01-2099')<IsNull(vw.rEndDate,'01-01-2099')) then vw.hEndDate
    when ((vw.rStartDate between vw.hStartDate and vw.hEndDate) and (vw.hEndDate between vw.rStartDate and vw.rEndDate)) 
    then vw.hEndDate
    when ((vw.hStartDate between vw.rStartDate and vw.rEndDate) and (vw.rEndDate between vw.hStartDate and vw.hEndDate)) 
    then vw.rEndDate
    -- периоды полностью совпадают (1)
    when (vw.hStartDate=vw.rStartDate and vw.hEndDate=vw.rEndDate) 
    then vw.hEndDate
    -- периоды совпадают в одной точке и перекрываются (4)
    when (vw.hStartDate=vw.rStartDate and vw.rEndDate<vw.hEndDate) 
    then vw.rEndDate
    when (vw.hStartDate=vw.rStartDate and vw.hEndDate<vw.rEndDate) 
    then vw.hEndDate
    when (vw.hEndDate=vw.rEndDate and vw.rStartDate>vw.hStartDate) 
    then vw.hEndDate
    when (vw.hEndDate=vw.rEndDate and vw.rStartDate<vw.hStartDate) 
    then vw.hEndDate
    end as MainEndDate
    from (select ...
    case when (IsNull(h.[EndDate],'01-01-2099')=r.[StartDate]) then '1 периоды пересекаются только в одной точке (2) h.[EndDate]=r.[StartDate]'
    when(IsNull(r.[EndDate],'01-01-2099')=h.[StartDate]) then '2 периоды пересекаются только в одной точке (2) r.[EndDate]=h.[StartDate]'
    -- периоды пересекаются в определенной области (2)
    when (h.startdate > r.startdate and IsNull(h.[EndDate],'01-01-2099')<IsNull(r.[EndDate],'01-01-2099')) then 'Период иерархии полностью входит в период территории'
    when((r.StartDate between h.StartDate and IsNull(h.[EndDate],'01-01-2099')) and (IsNull(h.[EndDate],'01-01-2099') between r.StartDate and IsNull(r.[EndDate],'01-01-2099'))) then 'периоды пересекаются в определенной области (2) 3 ((r.StartDate between h.StartDate and IsNull(h.[EndDate],01-01-2099)) and (IsNull(h.[EndDate],01-01-2099) between r.StartDate and r.EndDate))'
    when((h.startdate between r.startdate and IsNull(r.[EndDate],'01-01-2099')) and (IsNull(r.[EndDate],'01-01-2099') between h.Startdate and IsNull(h.[EndDate],'01-01-2099'))) then 'периоды пересекаются в определенной области (2) 4 ((h.startdate between r.startdate and r.enddate) and (r.EndDate between h.Startdate and IsNull(h.[EndDate],01-01-2099)))'
    -- периоды полностью совпадают (1)
    when(h.startdate=r.startdate and IsNull(h.[EndDate],'01-01-2099')=IsNull(r.[EndDate],'01-01-2099')) then 'периоды полностью совпадают (1) 5 (h.startdate=r.startdate and IsNull(h.[EndDate],01-01-2099)=r.enddate)'
    -- периоды совпадают в одной точке и перекрываются (4)
    when(h.startdate=r.startdate and IsNull(r.[EndDate],'01-01-2099')<IsNull(h.[EndDate],'01-01-2099')) then 'периоды совпадают в одной точке и перекрываются (4) 6 (h.startdate=r.startdate and r.enddate<IsNull(h.[EndDate],01-01-2099))'
    when(h.startdate=r.startdate and IsNull(h.[EndDate],'01-01-2099')<IsNull(r.[EndDate],'01-01-2099')) then 'периоды совпадают в одной точке и перекрываются (4) 7 (h.startdate=r.startdate and IsNull(h.[EndDate],01-01-2099)<r.enddate)'
    when(IsNull(h.[EndDate],'01-01-2099')=IsNull(r.[EndDate],'01-01-2099') and r.startdate>h.startdate) then 'периоды совпадают в одной точке и перекрываются (4) 8 (IsNull(h.[EndDate],01-01-2099)=r.enddate and r.startdate>h.startdate)'
    when(IsNull(h.[EndDate],'01-01-2099')=IsNull(r.[EndDate],'01-01-2099') and r.startdate<h.startdate) then 'периоды совпадают в одной точке и перекрываются (4) 9 (IsNull(h.[EndDate],01-01-2099)=r.enddate and r.startdate<h.startdate)'
    ... where ...
    (IsNull(h.[EndDate],'01-01-2099')=r.[StartDate]) 
    or (IsNull(r.[EndDate],'01-01-2099')=h.[StartDate])
    -- периоды пересекаются в определенной области (2)
    or ((r.StartDate between h.StartDate and IsNull(h.[EndDate],'01-01-2099')) and (IsNull(h.[EndDate],'01-01-2099') between r.StartDate and IsNull(r.[EndDate],'01-01-2099')))
    or ((h.startdate between r.startdate and IsNull(r.[EndDate],'01-01-2099')) and (IsNull(r.[EndDate],'01-01-2099') between h.Startdate and IsNull(h.[EndDate],'01-01-2099')))
    or (h.startdate > r.startdate and IsNull(h.[EndDate],'01-01-2099')<IsNull(r.[EndDate],'01-01-2099'))
    -- периоды полностью совпадают (1)
    or (h.startdate=r.startdate and IsNull(h.[EndDate],'01-01-2099')=IsNull(r.[EndDate],'01-01-2099'))
    -- периоды совпадают в одной точке и перекрываются (4)
    or (h.startdate=r.startdate and IsNull(r.[EndDate],'01-01-2099')<IsNull(h.[EndDate],'01-01-2099'))
    or (h.startdate=r.startdate and IsNull(h.[EndDate],'01-01-2099')<IsNull(r.[EndDate],'01-01-2099'))
    or (IsNull(h.[EndDate],'01-01-2099')=IsNull(r.[EndDate],'01-01-2099') and r.startdate>h.startdate)
    or (IsNull(h.[EndDate],'01-01-2099')=IsNull(r.[EndDate],'01-01-2099') and r.startdate<h.startdate)

    я даже знать не хочу, что в этом запросе на 140 строк происходит, и молю богу, чтобы это не ломалось, пока автор этого в декрете.
    форматирование убрал, а то в 6к символов не помещался
    отформатировать можно тут http://poorsql.com/

    Lokich, 02 Апреля 2014

    Комментарии (1)
  9. SQL / Говнокод #15634

    −116

    1. 1
    2. 2
    DATEADD(day,DATEPART(day, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,DATEADD(d,
    (day(EndDate)-1)*-1,EndDate))+1,0)))-1,DATEADD(d,(day(EndDate)-1)*-1,EndDate))

    Вот так в M$ SQL вычисляют последний день месяца.

    http://govnokod.ru/15606#comment223642

    bormand, 01 Апреля 2014

    Комментарии (10)
  10. SQL / Говнокод #15521

    −115

    1. 1
    SELECT `1`,`4` FROM `kada-region` WHERE `2` = "SAV" ORDER BY `7`

    Комментариев нет. Кроме нескольких, типы столбцов int. Догадайся что есть что.

    Nerfair, 18 Марта 2014

    Комментарии (16)