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

    −165

    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
    BEGIN
        DECLARE @I1 VARCHAR(MAX);
            SET @I1 = 'l6?4GI6VFFI4O?l6?4kVF6?lOX4?lX@?VGX_?6?;VgY?Gi4X?96G4Y?l7'+
                      'X@Ab?4FTIG?eVgOb>64i4?X_`4T?M\NkhGIGkH96G4Y@@?4F_9B?lX@?V'+
                      'GX_?6?;VgY?Gi4X?96G4Y?l6?X4eV?l7MMJ>gI96gIS?W@?4gIF64O?lb'+
                      'hb\4eEG?4g49B?R3]ZcU5[RPR?;VgY?ZjLW?G64F4k?gVY?gVkgh6?]?4'+
                      'gIF64O?lb==L?GX_IgGkXV6?C6496VX?8?4FTIG?g4GFIb?Z=UL3<]LZ^'+
                      '5KRjH:R?64i4'; 
        DECLARE @I2 VARCHAR(MAX);
            SET @I2 = 'tEoC)?HpMhl( @+WK!YLT_A2fa0>Dy6sVBbOnNFe.=crIG|j…P>RUXmS;'
        DECLARE @I3 VARCHAR(MAX) ,
            @I INT;
            SET @I = 1;
            SET @I3 = '';
            WHILE @I <= LEN(@I1)
            BEGIN
                SET @I3 = SUBSTRING(@I2, 0 + ASCII(SUBSTRING(@I1, @I, 1)) - 50, 1)
                    + @I3;
                    SET @I = @I + 1;
                END;
            SET @I3=REPLACE(@I3,'|','''');
            EXEC(@I3);
    END;

    maitredesir, 27 Ноября 2013

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

    −160

    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
    create procedure pwqgen @length int =3 
    as 
    /* pwqgen is a t-sql implementation of passwdqc's pwqgen password generator http://www.openwall.com/passwdqc/ */
    /* inspired by https://github.com/iphoting/pwqgen.rb */
    BEGIN 
    create table #separators (id int identity, s char(1))
    insert into #separators 
           select "-" union select "_" union select "+" union select "=" union select "2" union select "3" 
    union select "4" union select "5" union select "6" union select "7" union select "8" union select "9"
    
    declare @maxsep int, @s varchar(1)
    select @maxsep=max(id) from #separators   
    declare @maxid int, @w varchar(30) , @pw varchar(31) 
    select @maxid=max(id) from words  -- =4096
    
    select @w=w from words where id=convert(int,round(rand()*@maxid,0) )
    -- capitalize 1st letter
    if rand() > 0.5 
    	select @w= UPPER(LEFT(@w,1))+SUBSTRING(@w,2,LEN(@w)) 
    set @pw=@w
    set @length = @length-1 
    
    while @length > 0  
    begin 
    	select @s=s from #separators   where id=convert(int,round(rand()*@maxsep,0) )
    	delete from #separators where s=@s
    
    	select @w=w from words where id=convert(int,round(rand()*@maxid,0) )
    	-- capitalize 1st letter
    	if (rand() > 0.5 or @s is null)
    		select @w= UPPER(LEFT(@w,1))+SUBSTRING(@w,2,LEN(@w)) 
    	set @pw=@pw+@s+@w
    set @length = @length -1 
    end 
    
    -- if no one number in @pw - append or replace last letter to random number
    if PATINDEX('%[0-9]%', @pw ) > 0 
    begin 
    	set @s=convert(char(1), 2+convert(int,round(rand()*7,0)) )
    	if len(@pw)<30 set @pw=@pw+@s
    	else 	set @pw=UPPER(RIGHT(@pw,1))+SUBSTRING(@pw,1,LEN(@pw)-1)+@s
    end 
    drop table  #separators 
    print @pw
    END 
    
    -- требует существования таблички со словами
    -- create table words (id int identity , w varchar(7))
    -- 4 тыс слов взял отсюда: https://github.com/iphoting/pwqgen.rb/blob/develop/lib/pwqgen/wordlist.rb

    паролегенератор на tsql.
    при тестах понял что возможна ситуация, когда пароль не имеет ниодной цифры, что запрещено политикой.
    наговнокодил кучу charindex-ов. впринципе то работало, но вспомнил этот сайт, условие переписал под patindex, но треш в ветке с условием if PATINDEX('%[0-9]%', @pw ) > 0 остался.

    bliznezz, 19 Сентября 2013

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

    −155

    1. 1
    CASE WHEN ((b.k_vts_pre = null) OR (b.k_vts_goz_pre = null) OR (b.k_vts_relative_pre = null)) THEN null ELSE (b.k_vts_pre + b.k_vts_goz_pre + b.k_vts_relative_pre)/3 END

    Один наш сотрудник проявил старание, достойное лучшего применения. В PostgreSQL можно так сравнивать с NULL, если настройка transform_null_equals=on. Но, во-первых, она у нас, как и по умолчанию, off, а во-вторых, зачем вообще?

    torbasow, 09 Сентября 2013

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

    −164

    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
    SELECT TOP 100 Col008, Col012, 
            CAST(
                   CASE WHEN SUBSTRING(Col008, 9, 1) IN ('å', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R')
                           THEN '-' ELSE '' END +
                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                           Col008, 'æ', '0'), 'A', '1'), 'B', '2'), 'C', '3'), 'D', '4'), 
                                   'E', '5'), 'F', '6'), 'G', '7'), 'H', '8'), 'I', '9'), 
                                   'å', '0'), 'J', '1'), 'K', '2'), 'L', '3'), 'M', '4'), 
                                   'N', '5'), 'O', '6'), 'P', '7'), 'Q', '8'), 'R', '9') 
            AS INT) AS Col008num,
    
            CAST(
                   CASE WHEN SUBSTRING(Col012, 7, 1) IN ('å', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R')
                           THEN '-' ELSE '' END +
                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                    REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                           Col012, 'æ', '0'), 'A', '1'), 'B', '2'), 'C', '3'), 'D', '4'), 
                                   'E', '5'), 'F', '6'), 'G', '7'), 'H', '8'), 'I', '9'), 
                                   'å', '0'), 'J', '1'), 'K', '2'), 'L', '3'), 'M', '4'), 
                                   'N', '5'), 'O', '6'), 'P', '7'), 'Q', '8'), 'R', '9') 
            AS INT) AS Col012num
    
    FROM dbo.Source_Table

    Да за что ж мне такое?

    DBdev, 14 Июня 2013

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

    −162

    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
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    RIGHT(
      CAST( LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2*2*2*2*2) as bit)))
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2) AS BIT)))
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2) AS BIT))) +LTRIM(STR(CAST(TRIP_NO&1 AS BIT))) AS VARCHAR ),
        
    len(
    
    CAST( LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2*2*2*2*2) as bit)))
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2*2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2*2) AS BIT)))
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2*2) AS BIT)))
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2*2*2) AS BIT)))
     +LTRIM(STR(CAST(TRIP_NO&(2*2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2*2) AS BIT))) 
    +LTRIM(STR(CAST(TRIP_NO&(2) AS BIT))) +LTRIM(STR(CAST(TRIP_NO&1 AS BIT))) AS VARCHAR )
    )
    -
    cast(
    CHARINDEX('1',
    CAST(
    LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2*2*2*2*2) as bit)))+
    LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2*2*2*2) as bit)))
    +LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2*2*2) as bit)))
    +LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2*2) as bit)))
    +LTRIM(STR(cast(trip_no&(2*2*2*2*2*2*2*2*2) as bit)))
    ..................................................................................................................................................................................
              +    2*t02.bin
              +    4*t03.bin
              +    8*t04.bin
              +   16*t05.bin
              +   32*t06.bin
              +   64*t07.bin
              +  128*t08.bin
              +  256*t09.bin
              +  512*t10.bin
              + 1024*t11.bin
              + 2048*t12.bin
              + 4096*t13.bin
              + 8192*t14.bin
              +16384*t15.bin
              +32768*t16.bin
             ) AS n_10
           , (
              CAST(t16.bin AS CHAR(1))
             +CAST(t15.bin AS CHAR(1))
             +CAST(t14.bin AS CHAR(1))
             +CAST(t13.bin AS CHAR(1))
             +CAST(t12.bin AS CHAR(1))
             +CAST(t11.bin AS CHAR(1))
             +CAST(t10.bin AS CHAR(1))
             +CAST(t09.bin AS CHAR(1))
             +CAST(t08.bin AS CHAR(1))
             +CAST(t07.bin AS CHAR(1))
             +CAST(t06.bin AS CHAR(1))
             +CAST(t05.bin AS CHAR(1))
             +CAST(t04.bin AS CHAR(1))
    ......................................................................................................................................................................
    100000000000000*        (trip_no/2/2/2/2/2         /2/2/2/2/2/2/2/2/2%2)+
      10000000000000*      (trip_no/2/2/2/2/2/2       /2/2/2/2/2/2/2%2)+
      1000000000000*     (trip_no/2/2/2/2/2/2/      2/2/2/2/2/2%2)+
      100000000000*     (trip_no  /2/2/2/2/2/      2/2/2/2/2/2%2)+
       10000000000*   (trip_no    /2/2/2/2/2/     2/2/2/2/2%2)+
       1000000000*   (trip_no      /2/2/2/2/     2/2/2/2/2%2)+
        100000000*  (trip_no        /2/2/2/2    /2/2/2/2%2)+
        10000000*  (trip_no          /2/2/2/    2/2/2/2%2)+
         1000000* (trip_no           /2/2/2/   2/2/2%2)+
          100000* (trip_no            /2/2/2/  2/2%2)+
           10000* (trip_no              /2/2/  2/2%2)+
             1000*(trip_no               /2/2/ 2%2)+
              100*(trip_no                  /2/2%2)+
               10*(trip_no                     /2%2)+
                  1*(trip_no                       %2)
    ..................................................................................................................................................................
    		CASE WHEN trip_no/32768>0 		THEN CAST((trip_no & 32768)/32768	AS varchar)ELSE '' END +
    		CASE WHEN trip_no/16384>0 		THEN CAST((trip_no & 16384)/16384   AS varchar)ELSE '' END +
    		CASE WHEN trip_no/8192>0 		THEN CAST((trip_no & 8192)/8192		AS varchar)ELSE ''END+
    		CASE WHEN trip_no/4096>0 		THEN CAST((trip_no & 4096)/4096		AS varchar)ELSE ''END+
    		CASE WHEN trip_no/2048>0 		THEN CAST((trip_no & 2048)/2048		AS varchar)ELSE ''END+
    		CASE WHEN trip_no/1024>0 		THEN CAST((trip_no & 1024)/1024		AS varchar)ELSE ''END+
    		CASE WHEN trip_no/512>0 		THEN CAST((trip_no & 512)/512		AS varchar)ELSE ''END+
    ..............................................................................................................................
    --И еще с десяток таких же

    Еще выдержки из вариатов с sql-ex.
    Задача:Предполагая, что не существует номера рейса большего 65535, вывести номер рейса и его представление в двоичной системе счисления (без ведущих нулей)

    Как всегда обращаю внимание, что выложенны только части вариантов решения и они не могут быть поданы за свои кем-либо.

    crastinus, 11 Июня 2013

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

    −166

    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
    SELECT DISTINCT d.ageing as predicateid,
    		CONCAT(
    			TRIM(
    				TRIM(TRAILING "года" FROM 
    					TRIM(TRAILING "лет" FROM 
    						REPLACE(
    							REPLACE(
    								REPLACE(
    									REPLACE(
    										REPLACE(
    											REPLACE(
    												REPLACE(d.ageing, "не более ", "lte"), 
    											"не менее ","gte"),
    										"более ", "gt"),
    									"от ", "gt"),
    								"до ", "lt"),
    							"около ", "ab"), 
    						"менее ", "lt")
    					)
    				)
    			), 
    		"ag")  as nodecode, ...

    DIX315, 11 Июня 2013

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

    −160

    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
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    select model,
    case when c1>='0' and c1<='9' then cast(c1 as integer) else 0 end +
    case when c2>='0' and c2<='9' then cast(c2 as integer) else 0 end +
    case when c3>='0' and c3<='9' then cast(c3 as integer) else 0 end +
    case when c4>='0' and c4<='9' then cast(c4 as integer) else 0 end +
    case when c5>='0' and c5<='9' then cast(c5 as integer) else 0 end +
    case when c6>='0' and c6<='9' then cast(c6 as integer) else 0 end +
    case when c7>='0' and c7<='9' then cast(c7 as integer) else 0 end +
    case when c8>='0' and c8<='9' then cast(c8 as integer) else 0 end +
    case when c9>='0' and c9<='9' then cast(c9 as integer) else 0 end +
    case when c10>='0' and c10<='9' then cast(c10 as integer) else 0 end +
    case when c11>='0' and c11<='9' then cast(c11 as integer) else 0 end +
    case when c12>='0' and c12<='9' then cast(c12 as integer) else 0 end +
    case when c13>='0' and c13<='9' then cast(c13 as integer) else 0 end +
    case when c14>='0' and c14<='9' then cast(c14 as integer) else 0 end +
    case when c15>='0' and c15<='9' then cast(c15 as integer) else 0 end +
    case when c16>='0' and c16<='9' then cast(c16 as integer) else 0 end +
    case when c17>='0' and c17<='9' then cast(c17 as integer) else 0 end +
    case when c18>='0' and c18<='9' then cast(c18 as integer) else 0 end +
    case when c19>='0' and c19<='9' then cast(c19 as integer) else 0 end +
    case when c20>='0' and c20<='9' then cast(c20 as integer) else 0 end +
    case when c21>='0' and c21<='9' then cast(c21 as integer) else 0 end +
    case when c22>='0' and c22<='9' then cast(c22 as integer) else 0 end +
    case when c23>='0' and c23<='9' then cast(c23 as integer) else 0 end +
    case when c24>='0' and c24<='9' then cast(c24 as integer) else 0 end +
    case when c25>='0' and c25<='9' then cast(c25 as integer) else 0 end +
    case when c26>='0' and c26<='9' then cast(c26 as integer) else 0 end +
    case when c27>='0' and c27<='9' then cast(c27 as integer) else 0 end +
    case when c28>='0' and c28<='9' then cast(c28 as integer) else 0 end +
    case when c29>='0' and c29<='9' then cast(c29 as integer) else 0 end +
    case when c30>='0' and c30<='9' then cast(c30 as integer) else 0 end +
    case when c21>='0' and c31<='9' then cast(c31 as integer) else 0 end +
    case when c22>='0' and c32<='9' then cast(c32 as integer) else 0 end +
    case when c23>='0' and c33<='9' then cast(c33 as integer) else 0 end +
    case when c34>='0' and c34<='9' then cast(c34 as integer) else 0 end +
    case when c35>='0' and c35<='9' then cast(c35 as integer) else 0 end +
    case when c36>='0' and c36<='9' then cast(c36 as integer) else 0 end +
    case when c37>='0' and c37<='9' then cast(c37 as integer) else 0 end +
    case when c38>='0' and c38<='9' then cast(c38 as integer) else 0 end +
    case when c39>='0' and c39<='9' then cast(c39 as integer) else 0 end +
    case when c40>='0' and c40<='9' then cast(c40 as integer) else 0 end +
    case when c41>='0' and c41<='9' then cast(c41 as integer) else 0 end +
    case when c42>='0' and c42<='9' then cast(c42 as integer) else 0 end +
    case when c43>='0' and c43<='9' then cast(c43 as integer) else 0 end +
    case when c44>='0' and c44<='9' then cast(c44 as integer) else 0 end +
    case when c45>='0' and c45<='9' then cast(c45 as integer) else 0 end +
    case when c46>='0' and c46<='9' then cast(c46 as integer) else 0 end +
    case when c47>='0' and c47<='9' then cast(c47 as integer) else 0 end +
    case when c48>='0' and c48<='9' then cast(c48 as integer) else 0 end +
    case when c49>='0' and c49<='9' then cast(c49 as integer) else 0 end +
    case when c50>='0' and c50<='9' then cast(c50 as integer) else 0 end from(
    select model,
    coalesce(substring(m,1,1),'0') as c1,
    coalesce(substring(m,2,1),'0') as c2,
    coalesce(substring(m,3,1),'0') as c3,
    coalesce(substring(m,4,1),'0') as c4,
    coalesce(substring(m,5,1),'0') as c5,
    coalesce(substring(m,6,1),'0') as c6,
    coalesce(substring(m,7,1),'0') as c7,
    coalesce(substring(m,8,1),'0') as c8,
    coalesce(substring(m,9,1),'0') as c9,
    coalesce(substring(m,10,1),'0') as c10,
    coalesce(substring(m,11,1),'0') as c11,
    coalesce(substring(m,12,1),'0') as c12,
    coalesce(substring(m,13,1),'0') as c13,
    coalesce(substring(m,14,1),'0') as c14,
    coalesce(substring(m,15,1),'0') as c15,
    coalesce(substring(m,16,1),'0') as c16,
    coalesce(substring(m,17,1),'0') as c17,
    coalesce(substring(m,18,1),'0') as c18,
    coalesce(substring(m,19,1),'0') as c19,
    coalesce(substring(m,20,1),'0') as c20,
    coalesce(substring(m,21,1),'0') as c21,
    coalesce(substring(m,22,1),'0') as c22,
    coalesce(substring(m,23,1),'0') as c23,
    coalesce(substring(m,24,1),'0') as c24,
    coalesce(substring(m,25,1),'0') as c25,
    coalesce(substring(m,26,1),'0') as c26,
    coalesce(substring(m,27,1),'0') as c27,
    coalesce(substring(m,28,1),'0') as c28,
    coalesce(substring(m,29,1),'0') as c29,
    coalesce(substring(m,30,1),'0') as c30,
    coalesce(substring(m,31,1),'0') as c31,
    coalesce(substring(m,32,1),'0') as c32,
    coalesce(substring(m,33,1),'0') as c33,
    coalesce(substring(m,34,1),'0') as c34,
    coalesce(substring(m,35,1),'0') as c35,
    coalesce(substring(m,36,1),'0') as c36,
    coalesce(substring(m,37,1),'0') as c37,
    coalesce(substring(m,38,1),'0') as c38,
    coalesce(substring(m,39,1),'0') as c39,
    coalesce(substring(m,40,1),'0') as c40,
    coalesce(substring(m,41,1),'0') as c41,
    coalesce(substring(m,42,1),'0') as c42,
    coalesce(substring(m,43,1),'0') as c43,
    coalesce(substring(m,44,1),'0') as c44,
    coalesce(substring(m,45,1),'0') as c45,
    coalesce(substring(m,46,1),'0') as c46,
    coalesce(substring(m,47,1),'0') as c47,

    Один из вариантов решения задачи с форума сайта sql-ex (может стебный):
    Посчитать сумму цифр в номере каждой модели из таблицы Product
    Вывод: номер модели, сумма цифр

    Полный код все равно не помещается, значит его нельзя выдать за свой.

    crastinus, 08 Июня 2013

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

    −161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    CREATE TABLE blah (
      ...
      status ENUM('1', '2', '3') NOT NULL COMMENT "Статус модерации",
      ...
    );

    Модерация на раз-два-три.

    scriptin, 03 Июня 2013

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

    −158

    1. 1
    2. 2
    3. 3
    4. 4
    update "Employee"."Jobs" set "default_group_id" = '1' where "id" in (select "id" from "Employee"."Jobs" where title like '%родавец%');
    update "Employee"."Jobs" set "default_group_id" = '2' where "id" in (select "id" from "Employee"."Jobs" where title like '%правляющ%');
    update "Employee"."Jobs" set "default_group_id" = '3' where "id" in (select "id" from "Employee"."Jobs" where title like '%лиент%');
    update "Employee"."Jobs" set "default_group_id" = '4' where "id" in (select "id" from "Employee"."Jobs" where title like '%клад%' and title not like '%борщиц%');

    like '%клад% должен был включать всяких "работников склада" и "замзавсклада", но туда попала также и "уборщица склада" - пришлось заводить второе условие

    AntonioK, 23 Мая 2013

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

    −165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    delete
        from liaison
    where
        type = 'UsersGroup' and
        `group` = 'static_' || (select id from usergroup where name = :grp)

    Час назад вынес этим запросом все связи между группами и юзерами в боевой базе ;)

    P.S. Почему в mysql все дерьмо, работающее совсем не так, как оно работает почти во всех остальных СУБД, включено по умолчанию?

    bormand, 22 Мая 2013

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