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

    +1

    1. 1
    n := trunc(sysdate) - trunc(sysdate-2);

    PL/SQL. Вендорская поддержка. Гениальное просто.

    mishok, 23 Марта 2017

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

    +267

    1. 1
    2. 2
    3. 3
    CREATE FUNCTION this_function_check_first_payment_under_agreement_without_previous_periods
    (
    ....

    Ну вот сразу всё понятно)

    Onimys, 17 Августа 2016

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

    +952

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    declare @col int
    set @col = 0
    
    while (select count(distinct id) from #tovar) > @col
    begin
    set @col = (select count(distinct id) from #tovar)
    	insert into #tovar (ParentID, ID, ISFOLDER, Tov) select parentID, ID, ISFOLDER, DESCR from SC23(nolock) where ISMARK = 0 and PARENTID in (select id from #tovar) 
    end

    dsfix, 30 Июля 2015

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

    +92

    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
    SELECT     top 20 *,
    		CAST(DATEPART(yy, rs_message_sendtime) AS varchar(4)) + '-' + (CASE WHEN len(CAST(DATEPART(m, 
                          rs_message_sendtime) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(m, rs_message_sendtime) AS varchar(4)) ELSE CAST(DATEPART(m, 
                          rs_message_sendtime) AS varchar(4)) END) + '-' + (CASE WHEN (len(CAST(DATEPART(d, rs_message_sendtime) AS varchar(4)))) 
                          = 1 THEN '0' + CAST(DATEPART(d, rs_message_sendtime) AS varchar(4)) ELSE CAST(DATEPART(d, rs_message_sendtime) AS varchar(4)) END) 
                          + 'T' + (CASE WHEN len(CAST(DATEPART(hh, rs_message_sendtime) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(hh, rs_message_sendtime) 
                          AS varchar(4)) ELSE CAST(DATEPART(hh, rs_message_sendtime) AS varchar(4)) END) + ':' + (CASE WHEN len(CAST(DATEPART(mi, 
                          rs_message_sendtime) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(mi, rs_message_sendtime) AS varchar(4)) ELSE CAST(DATEPART(mi, 
                          rs_message_sendtime) AS varchar(4)) END) + ':' + (CASE WHEN len(CAST(DATEPART(ss, rs_message_sendtime) AS varchar(4))) 
                          = 1 THEN '0' + CAST(DATEPART(ss, rs_message_sendtime) AS varchar(4)) ELSE CAST(DATEPART(ss, rs_message_sendtime) AS varchar(4)) END) 
                          AS sendtime, 
    					  CAST(DATEPART(yy, rs_message_valid_from) AS varchar(4)) + '-' + (CASE WHEN len(CAST(DATEPART(m, rs_message_valid_from) 
                          AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(m, rs_message_valid_from) AS varchar(4)) ELSE CAST(DATEPART(m, rs_message_valid_from) 
                          AS varchar(4)) END) + '-' + (CASE WHEN (len(CAST(DATEPART(d, rs_message_valid_from) AS varchar(4)))) = 1 THEN '0' + CAST(DATEPART(d, 
                          rs_message_valid_from) AS varchar(4)) ELSE CAST(DATEPART(d, rs_message_valid_from) AS varchar(4)) END) 
                          + 'T' + (CASE WHEN len(CAST(DATEPART(hh, rs_message_valid_from) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(hh, rs_message_valid_from) 
                          AS varchar(4)) ELSE CAST(DATEPART(hh, rs_message_valid_from) AS varchar(4)) END) + ':' + (CASE WHEN len(CAST(DATEPART(mi, 
                          rs_message_valid_from) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(mi, rs_message_valid_from) AS varchar(4)) ELSE CAST(DATEPART(mi, 
                          rs_message_valid_from) AS varchar(4)) END) + ':' + (CASE WHEN len(CAST(DATEPART(ss, rs_message_valid_from) AS varchar(4))) 
                          = 1 THEN '0' + CAST(DATEPART(ss, rs_message_valid_from) AS varchar(4)) ELSE CAST(DATEPART(ss, rs_message_valid_from) AS varchar(4)) END) 
                          AS validfrom, 
    					  CAST(DATEPART(yy, rs_message_valid_to) AS varchar(4)) + '-' + (CASE WHEN len(CAST(DATEPART(m, rs_message_valid_to) 
                          AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(m, rs_message_valid_to) AS varchar(4)) ELSE CAST(DATEPART(m, rs_message_valid_to) AS varchar(4)) 
                          END) + '-' + (CASE WHEN (len(CAST(DATEPART(d, rs_message_valid_to) AS varchar(4)))) = 1 THEN '0' + CAST(DATEPART(d, rs_message_valid_to) 
                          AS varchar(4)) ELSE CAST(DATEPART(d, rs_message_valid_to) AS varchar(4)) END) + 'T' + (CASE WHEN len(CAST(DATEPART(hh, rs_message_valid_to) 
                          AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(hh, rs_message_valid_to) AS varchar(4)) ELSE CAST(DATEPART(hh, rs_message_valid_to) 
                          AS varchar(4)) END) + ':' + (CASE WHEN len(CAST(DATEPART(mi, rs_message_valid_to) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(mi, 
                          rs_message_valid_to) AS varchar(4)) ELSE CAST(DATEPART(mi, rs_message_valid_to) AS varchar(4)) END) 
                          + ':' + (CASE WHEN len(CAST(DATEPART(ss, rs_message_valid_to) AS varchar(4))) = 1 THEN '0' + CAST(DATEPART(ss, rs_message_valid_to) 
                          AS varchar(4)) ELSE CAST(DATEPART(ss, rs_message_valid_to) AS varchar(4)) END) AS validto
    					  
    FROM         rs_message_outbox_ready INNER JOIN
                          rs_customer_feed ON rs_customer_feed.rs_customer_feed_id = rs_message_outbox_ready.rs_customer_feed_id INNER JOIN
                          rs_customer ON rs_message_outbox_ready.rs_customer_id = rs_customer.rs_customer_id
    	WHERE     
    	(rs_message_outbox_ready.rs_message_sendtime <= GETDATE()) AND
    	(rs_message_outbox_ready.rs_message_type = 2) AND 
    	(rs_customer_feed.rs_customer_feed_status = 1) AND 
    	(rs_customer.rs_customer_status = 1) AND 
    	(rs_customer_feed.rs_customer_feed_category = 2) AND 
    	(rs_message_outbox_ready.rs_message_status = 5) AND
    	(rs_customer_feed.rs_customer_feed_xml=1)

    Переводим дату из одного формата в другой :)

    kropotor, 17 Июля 2015

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

    +93

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    select 
    case 
      when count(*) > 0 then '1' 
      else '0' end 
    as "T"  
    from sometable   where searchcode = 'value'

    EXISTS? не, не слышал

    bliznezz, 10 Июля 2015

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

    +92

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    ...
    LOWER(stuff_tags) LIKE "'.addslashes($_GET['q']).',%" OR
    LOWER(stuff_tags) LIKE "%,'.addslashes($_GET['q']).'" OR
    LOWER(stuff_tags) LIKE "%,'.addslashes($_GET['q']).',%" OR
    LOWER(stuff_tags) = "'.addslashes($_GET['q']).'" 
    ...

    В проекте какого-то школьника.

    damir, 09 Июля 2015

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

    +95

    1. 1
    n IN (6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)

    условие n >= 6 выполнено

    lisiy50, 02 Июля 2015

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

    +94

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    BEGIN
    select count(*) INTO var FROM table_name;
    EXCEPTION WHEN OTHERS THEN 
    var:=0;
    END;

    Если что-то пойдет не так...
    P.S.: count() всегда возвращает какое-либо значение. Ошибке не откуда взяться.

    mishok, 01 Июля 2015

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

    +79

    1. 1
    and (ss_1<>'SS0001' or ss_1<>'SS0002' or ss_1<>'SS0010')

    Сегодня на продакшене было обнаружено гениальное выражение в одном из запросов.

    mishok, 01 Июля 2015

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

    +95

    1. 1
    2. 2
    ALTER TABLE db.table ADD CONSTRAINT cu_contents UNIQUE (contents(128));
    ALTER TABLE db.table DROP INDEX cu_contents;

    Создал констрейнт, удал индекс. Загадки Майсиквела.

    wvxvw, 30 Июня 2015

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