• Foreign Student (unregistered)

    Need URGENT code to Count off business days between two dates for school and find yor saite in googles, PLEAZE SEND TEH CODEZ!

  • (cs) in reply to Henrik
    Henrik:
    This code is written by some evil person who want everyone that looks at it to commit suicide.
    I hear that after seeing this code, you die in seven days.
  • sf (unregistered)

    My guess is that it's supposed to indicate whether or not a ticket will be closed out in the required maximum number of weeks based on priority: med <= 5 weeks, low <= 10 weeks.

    Would I be the only one who thinks that the use of spaces and such in the column names (so the query results have a nice header layout) is a bigger WTF than the code logic? How can somebody write something like this and not know how to use an aliases in a query?

  • nullpointer (unregistered)

    this cant be real...

  • (cs) in reply to Benanov
    Benanov:
    H: This is actually a fragment of SQL code for determining an extremely accurate 5-year projection on Stock Prices.

    Unfortunately, it takes 5 years to run.

    No, no, that's most unfair. All it needs is an index on "Help Desk Attributes"."TAT" (rather well-named, that, I feel), "Help Desk Attributes"."Priority", and that "Day of Week" thing.

    This is actually the first WTF that makes me want to go back to programming in Z80 Assembler.

    Any chance of storing it under "Classics?"

  • (cs) in reply to Vollhorst

    That's not the only valid way. Consider a regexp A. If A matches against valid emails, so does A.{0}. By induction, there are infinitely many valid regular expressions to accept the grammar of emails.

  • (cs)

    FILE NOT FOUND On a wooden table For Paula (Brillant) Bean With XML Not in VB

  • Regex User (unregistered) in reply to Vollhorst

    At least the regex wasn't generated by hand, but rather coded up by following the patterns in the RFC. And, weirdly enough, there's nothing unnecessary in it.

    Doesn't stop it from looking scary, though!

  • (cs) in reply to tekiegreg
    tekiegreg:
    Maybe I should somewhat obfuscate and share the 1500 line 12 UNION'd, multi join on subquery monster that I get to occasionally deal with in my job....I'd almost wish for today's WTF...

    Damn you! Here I thought the 500 line SELECT I helped write was bad. I am obviously spoiled.

  • (cs) in reply to sf
    sf:
    My guess is that it's supposed to indicate whether or not a ticket will be closed out in the required maximum number of weeks based on priority: med <= 5 weeks, low <= 10 weeks.
    Close. It seems to be more of a "completed on time" function, return 1 if true, 0 if false (very traditional ;^) ). The time limits are 5 or 10 days, which makes any code that looks at whether a ticket took more than 7 days to complete (which a lot of this does) totally superfluous...
    sf:
    Would I be the only one who thinks that the use of spaces and such in the column names (so the query results have a nice header layout) is a bigger WTF than the code logic? How can somebody write something like this and not know how to use an aliases in a query?
    You probably aren't the only person to think that, but you're probably wrong. The code logic is horrible, makes unnecessary calculations (like working out how many non-work days have passed for tickets that took up to 19 days to complete when the SLA is 5 working days) and can probably be done with some kind of built-in date function (I don't know T-SQL off the top of my head, so I can't quote one). The table and field names are clunky and unweildy, but they're only a WTF in their own right once you have to write them out a couple of hundred times in this horrifically twisted logic...
  • (cs)

    I don't have any pencils. Is whiteboard marker okay?

  • Quiz taker (unregistered) in reply to Eternal Density

    uhhhhh...[rocks back and forth slowly]...I just died a little on the inside. Even using only the w3 SQL tutorial, someone should be able to write better code than that...I did (clarification, I'm not in IT, it was for a personal project).

  • (cs) in reply to JimM
    JimM:
    sf:
    My guess is that it's supposed to indicate whether or not a ticket will be closed out in the required maximum number of weeks based on priority: med <= 5 weeks, low <= 10 weeks.
    Close. It seems to be more of a "completed on time" function, return 1 if true, 0 if false (very traditional ;^) ). The time limits are 5 or 10 days, which makes any code that looks at whether a ticket took more than 7 days to complete (which a lot of this does) totally superfluous...
    sf:
    Would I be the only one who thinks that the use of spaces and such in the column names (so the query results have a nice header layout) is a bigger WTF than the code logic? How can somebody write something like this and not know how to use an aliases in a query?
    You probably aren't the only person to think that, but you're probably wrong. The code logic is horrible, makes unnecessary calculations (like working out how many non-work days have passed for tickets that took up to 19 days to complete when the SLA is 5 working days) and can probably be done with some kind of built-in date function (I don't know T-SQL off the top of my head, so I can't quote one). The table and field names are clunky and unweildy, but they're only a WTF in their own right once you have to write them out a couple of hundred times in this horrifically twisted logic...

    Here's the logic in compressed form. Yeah, on reflection, it looks like N represents the number of non-work days to subtract.

         if medium priority and TTCD - N >=  5 then 1
    else if    low priority and TTCD - N >= 10 then 1
    else 0
    
               N = 0       | 1      | 2       | 3       | 4        | 5        | 6
    
            TTCD = ...
    
      OD.DIW = 1:  0       | 1 to 5 | 6       | 7 to 12 | 13       | 14 to 19 | 
               2:  -1 to 4 | 5      | 6 to 11 | 12      | 13 to 18 |          | 
               3:  -1 to 3 | 4      | 5 to 10 | 11      | 12 to 17 |          | 
               4:  -1 to 2 | 3      | 4 to  9 | 10      | 11 to 16 |          | 
               5:  -1 to 1 | 2      | 3 to  8 |  9      | 10 to 15 |          | 
               6:  -1 to 0 | 1      | 2 to  7 |  8      |  9 to 14 |          | 
               7:  -1 to 0 | 1      | 2 to  6 |  7      |  8 to 13 | 14       | 15 to 20
    
    Anything off the table gives N = 0.
    
    Assuming the obvious two corrections for OD.DIW = 7, N = 2.
    

    You could combine DATEDIFF and DATEADD, but it would still be kind of ugly. The old-schoolers on Usenet suggest the following alternate approach:

    • Create a table containing all dates over a suitable range (e.g. 2000 through 2099). Make sure no one but the sysadmin can delete rows from it.

    • Flag weekends and holidays (using computed columns when feasible, manual flags otherwise).

    • Count the number of flagged dates falling within the time period in question, and subtract that from the total number of days.

  • (cs)

    Um... uh... dies

  • Jon (unregistered) in reply to Vollhorst
    Vollhorst:
    Reminds me of the only valid way to validate email addresses with regular expressions:

    (demented regular expression snipped)

    That's autogenerated, obfuscated, and doesn't work on email addresses with enough nested comments.

    I came up with this a while back. It sticks to the RFC, except for the obvious mistake (where a quoted-pair matches text of any length beginning with a backslash and not containing a a CRLF pair). My code almost certainly has errors, but the point is that even without errors it wouldn't be very long at all.

    sub isvalidemail {
    $_ = shift;
    if (/[\x80-\xff]/) { return 0; }
    if ($_ !~ /^(.)@([^@])$/s) { return 0; }
    my ($addr, $domain) = ($1, $2);
    $ws = '(\r\n[ \t]+|[ \t]+(\r\n[ \t]+))?';
    $comment = '(('.$ws.'([^\x00\t\r\n ()*\\]|\\.))'.$ws.')';
    $word = $ws.'([!#-'+-/-9=?A-Z^-~]+|"('.$ws.'([^\x00\t\r\n "\\]|\\.))'.$ws.'")'.$ws;
    while ($addr =~ s/^((\.|"(\.|[^\"])"|[^\"]))$comment/\1/s) { }
    if ($addr !~ /^($word(.$word))$/s) { return 0; }
    while ($domain =~ s/^([^[(]|[[^]]])$comment/$1/s) { }
    $obs_domain = '[!#-'+-/-9=?A-Z^-~]+('.$ws.'.'.$ws.'[!#-'+-/-9=?A-Z^-~]+)';
    return $domain =~ /^$ws([($ws([^\x00\t\r\n [\]]|\.))*$ws]|$obs_domain)$ws$/s;
    }

  • (cs) in reply to Brad
    Brad:
    StarLite:
    I guess it would be a a lot better if it was indented properly.

    (CASE WHEN "Help Desk Attributes".Priority = '3-Medium' AND ("Help Desk Attributes"."TAT To Close - Days" - (Case WHEN "- Open Date"."Day in Week" = 1 AND "Help Desk Attributes"."TAT To Close - Days" = 0 THEN 0 WHEN "- Open Date"."Day in Week" = 1 AND "Help Desk Attributes"."TAT To Close - Days" <= 5 THEN 1 WHEN "- Open Date"."Day in Week" = 1 AND "Help Desk Attributes"."TAT To Close - Days" = 6 THEN 2 WHEN "- Open Date"."Day in Week" = 1 AND "Help Desk Attributes"."TAT To Close - Days" <= 12 THEN 3 WHEN "- Open Date"."Day in Week" = 1 AND "Help Desk Attributes"."TAT To Close - Days" = 13 THEN 4 WHEN "- Open Date"."Day in Week" = 1 AND "Help Desk Attributes"."TAT To Close - Days" <= 19 THEN 5 WHEN "- Open Date"."Day in Week" = 2 AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 AND 4 THEN 0 WHEN "- Open Date"."Day in Week" = 2 AND "Help Desk Attributes"."TAT To Close - Days" = 5 THEN 1 WHEN "- Open Date"."Day in Week" = 2 AND "Help Desk Attributes"."TAT To Close - Days" <= 11 THEN 2 WHEN "- Open Date"."Day in Week" = 2 AND "Help Desk Attributes"."TAT To Close - Days" = 12 THEN 3 WHEN "- Open Date"."Day in Week" = 2 AND "Help Desk Attributes"."TAT To Close - Days" <= 18 THEN 4 WHEN "- Open Date"."Day in Week" = 3 AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 AND 3 THEN 0 WHEN "- Open Date"."Day in Week" = 3 AND "Help Desk Attributes"."TAT To Close - Days" = 4 THEN 1 WHEN "- Open Date"."Day in Week" = 3 AND "Help Desk Attributes"."TAT To Close - Days" <= 10 THEN 2 WHEN "- Open Date"."Day in Week" = 3 AND "Help Desk Attributes"."TAT To Close - Days" = 11 THEN 3 WHEN "- Open Date"."Day in Week" = 3 AND "Help Desk Attributes"."TAT To Close - Days" <= 17 THEN 4 WHEN "- Open Date"."Day in Week" = 4 AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 AND 2 THEN 0 WHEN "- Open Date"."Day in Week" = 4 AND "Help Desk Attributes"."TAT To Close - Days" = 3 THEN 1 WHEN "- Open Date"."Day in Week" = 4 AND "Help Desk Attributes"."TAT To Close - Days" <= 9 THEN 2 WHEN "- Open Date"."Day in Week" = 4 AND "Help Desk Attributes"."TAT To Close - Days" = 10 THEN 3 WHEN "- Open Date"."Day in Week" = 4 AND "Help Desk Attributes"."TAT To Close - Days" <= 16 THEN 4 WHEN "- Open Date"."Day in Week" = 5 AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 AND 1 THEN 0 WHEN "- Open Date"."Day in Week" = 5 AND "Help Desk Attributes"."TAT To Close - Days" = 2 THEN 1 WHEN "- Open Date"."Day in Week" = 5 AND "Help Desk Attributes"."TAT To Close - Days" <= 8 THEN 2 WHEN "- Open Date"."Day in Week" = 5 AND "Help Desk Attributes"."TAT To Close - Days" = 9 THEN 3 WHEN "- Open Date"."Day in Week" = 5 AND "Help Desk Attributes"."TAT To Close - Days" <= 15 THEN 4 WHEN "- Open Date"."Day in Week" = 6 AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 6 AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" = 6 AND "Help Desk Attributes"."TAT To Close - Days" <= 7 THEN 2 WHEN "- Open Date"."Day in Week" = 6 AND "Help Desk Attributes"."TAT To Close - Days" = 8 THEN 3 WHEN "- Open Date"."Day in Week" = 6 AND "Help Desk Attributes"."TAT To Close - Days" <= 14 THEN 4 WHEN "- Open Date"."Day in Week" = 7 AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 7 AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" <= 7 AND "Help Desk Attributes"."TAT To Close - Days" <= 76 THEN 2 WHEN "- Open Date"."Day in Week" = 7 AND "Help Desk Attributes"."TAT To Close - Days" = 7 THEN 3 WHEN "- Open Date"."Day in Week" = 7 AND "Help Desk Attributes"."TAT To Close - Days" <= 13 THEN 4 WHEN "- Open Date"."Day in Week" = 7 AND "Help Desk Attributes"."TAT To Close - Days" = 14 THEN 5 WHEN "- Open Date"."Day in Week" = 7 AND "Help Desk Attributes"."TAT To Close - Days" <= 20 THEN 6 ELSE 0 END)) <= 5 THEN 1

    	WHEN "Help Desk Attributes".Priority = '4-Low' 
    	AND ("Help Desk Attributes"."TAT To Close - Days" - (Case WHEN "- Open Date"."Day in Week" = 1 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 0 THEN 0 WHEN "- Open Date"."Day in Week" = 1 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 5 THEN 1 WHEN "- Open Date"."Day in Week" = 1 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 6 THEN 2 WHEN "- Open Date"."Day in Week" = 1 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 12 THEN 3 WHEN "- Open Date"."Day in Week" = 1 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 13 THEN 4 WHEN "- Open Date"."Day in Week" = 1 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 19 THEN 5 WHEN "- Open Date"."Day in Week" = 2 
    	AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    	AND 4 THEN 0 WHEN "- Open Date"."Day in Week" = 2 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 5 THEN 1 WHEN "- Open Date"."Day in Week" = 2 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 11 THEN 2 WHEN "- Open Date"."Day in Week" = 2 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 12 THEN 3 WHEN "- Open Date"."Day in Week" = 2 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 18 THEN 4 WHEN "- Open Date"."Day in Week" = 3 
    	AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    	AND 3 THEN 0 WHEN "- Open Date"."Day in Week" = 3 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 4 THEN 1 WHEN "- Open Date"."Day in Week" = 3 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 10 THEN 2 WHEN "- Open Date"."Day in Week" = 3 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 11 THEN 3 WHEN "- Open Date"."Day in Week" = 3 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 17 THEN 4 WHEN "- Open Date"."Day in Week" = 4 
    	AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    	AND 2 THEN 0 WHEN "- Open Date"."Day in Week" = 4 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 3 THEN 1 WHEN "- Open Date"."Day in Week" = 4 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 9 THEN 2 WHEN "- Open Date"."Day in Week" = 4 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 10 THEN 3 WHEN "- Open Date"."Day in Week" = 4 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 16 THEN 4 WHEN "- Open Date"."Day in Week" = 5 
    	AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    	AND 1 THEN 0 WHEN "- Open Date"."Day in Week" = 5 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 2 THEN 1 WHEN "- Open Date"."Day in Week" = 5 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 8 THEN 2 WHEN "- Open Date"."Day in Week" = 5 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 9 THEN 3 WHEN "- Open Date"."Day in Week" = 5 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 15 THEN 4 WHEN "- Open Date"."Day in Week" = 6 
    	AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    	AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 6 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" = 6 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 7 THEN 2 WHEN "- Open Date"."Day in Week" = 6 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 8 THEN 3 WHEN "- Open Date"."Day in Week" = 6 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 14 THEN 4 WHEN "- Open Date"."Day in Week" = 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    	AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" <= 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 76 THEN 2 WHEN "- Open Date"."Day in Week" = 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 7 THEN 3 WHEN "- Open Date"."Day in Week" = 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 13 THEN 4 WHEN "- Open Date"."Day in Week" = 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" = 14 THEN 5 WHEN "- Open Date"."Day in Week" = 7 
    	AND "Help Desk Attributes"."TAT To Close - Days" <= 20 THEN 6 ELSE 0 
    	END)) <= 10 THEN 1 ELSE 0 
    

    END)

    Still quite WTF tho ;)

    Addendum (2008-04-02 08:40): I guess it would be a a lot better if it was indented properly.

    (CASE 
    	WHEN "Help Desk Attributes".Priority = '3-Medium' AND 
    		("Help Desk Attributes"."TAT To Close - Days" - 
    			(Case 
    			WHEN "- Open Date"."Day in Week" = 1 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 0 THEN 0 WHEN "- Open Date"."Day in Week" = 1 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 5 THEN 1 WHEN "- Open Date"."Day in Week" = 1 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 6 THEN 2 WHEN "- Open Date"."Day in Week" = 1 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 12 THEN 3 WHEN "- Open Date"."Day in Week" = 1 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 13 THEN 4 WHEN "- Open Date"."Day in Week" = 1 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 19 THEN 5 WHEN "- Open Date"."Day in Week" = 2 
    			AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    			AND 4 THEN 0 WHEN "- Open Date"."Day in Week" = 2 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 5 THEN 1 WHEN "- Open Date"."Day in Week" = 2 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 11 THEN 2 WHEN "- Open Date"."Day in Week" = 2 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 12 THEN 3 WHEN "- Open Date"."Day in Week" = 2 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 18 THEN 4 WHEN "- Open Date"."Day in Week" = 3 
    			AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    			AND 3 THEN 0 WHEN "- Open Date"."Day in Week" = 3 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 4 THEN 1 WHEN "- Open Date"."Day in Week" = 3 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 10 THEN 2 WHEN "- Open Date"."Day in Week" = 3 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 11 THEN 3 WHEN "- Open Date"."Day in Week" = 3 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 17 THEN 4 WHEN "- Open Date"."Day in Week" = 4 
    			AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    			AND 2 THEN 0 WHEN "- Open Date"."Day in Week" = 4 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 3 THEN 1 WHEN "- Open Date"."Day in Week" = 4 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 9 THEN 2 WHEN "- Open Date"."Day in Week" = 4 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 10 THEN 3 WHEN "- Open Date"."Day in Week" = 4 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 16 THEN 4 WHEN "- Open Date"."Day in Week" = 5 
    			AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    			AND 1 THEN 0 WHEN "- Open Date"."Day in Week" = 5 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 2 THEN 1 WHEN "- Open Date"."Day in Week" = 5 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 8 THEN 2 WHEN "- Open Date"."Day in Week" = 5 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 9 THEN 3 WHEN "- Open Date"."Day in Week" = 5 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 15 THEN 4 WHEN "- Open Date"."Day in Week" = 6 
    			AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    			AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 6 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" = 6 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 7 THEN 2 WHEN "- Open Date"."Day in Week" = 6 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 8 THEN 3 WHEN "- Open Date"."Day in Week" = 6 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 14 THEN 4 WHEN "- Open Date"."Day in Week" = 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    			AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" <= 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 76 THEN 2 WHEN "- Open Date"."Day in Week" = 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 7 THEN 3 WHEN "- Open Date"."Day in Week" = 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 13 THEN 4 WHEN "- Open Date"."Day in Week" = 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" = 14 THEN 5 WHEN "- Open Date"."Day in Week" = 7 
    			AND "Help Desk Attributes"."TAT To Close - Days" <= 20 THEN 6 ELSE 0 
    			END)) <= 5 THEN 1 
    			
    		WHEN "Help Desk Attributes".Priority = '4-Low' 
    		AND ("Help Desk Attributes"."TAT To Close - Days" - (Case WHEN "- Open Date"."Day in Week" = 1 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 0 THEN 0 WHEN "- Open Date"."Day in Week" = 1 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 5 THEN 1 WHEN "- Open Date"."Day in Week" = 1 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 6 THEN 2 WHEN "- Open Date"."Day in Week" = 1 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 12 THEN 3 WHEN "- Open Date"."Day in Week" = 1 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 13 THEN 4 WHEN "- Open Date"."Day in Week" = 1 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 19 THEN 5 WHEN "- Open Date"."Day in Week" = 2 
    		AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    		AND 4 THEN 0 WHEN "- Open Date"."Day in Week" = 2 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 5 THEN 1 WHEN "- Open Date"."Day in Week" = 2 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 11 THEN 2 WHEN "- Open Date"."Day in Week" = 2 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 12 THEN 3 WHEN "- Open Date"."Day in Week" = 2 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 18 THEN 4 WHEN "- Open Date"."Day in Week" = 3 
    		AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    		AND 3 THEN 0 WHEN "- Open Date"."Day in Week" = 3 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 4 THEN 1 WHEN "- Open Date"."Day in Week" = 3 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 10 THEN 2 WHEN "- Open Date"."Day in Week" = 3 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 11 THEN 3 WHEN "- Open Date"."Day in Week" = 3 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 17 THEN 4 WHEN "- Open Date"."Day in Week" = 4 
    		AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    		AND 2 THEN 0 WHEN "- Open Date"."Day in Week" = 4 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 3 THEN 1 WHEN "- Open Date"."Day in Week" = 4 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 9 THEN 2 WHEN "- Open Date"."Day in Week" = 4 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 10 THEN 3 WHEN "- Open Date"."Day in Week" = 4 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 16 THEN 4 WHEN "- Open Date"."Day in Week" = 5 
    		AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    		AND 1 THEN 0 WHEN "- Open Date"."Day in Week" = 5 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 2 THEN 1 WHEN "- Open Date"."Day in Week" = 5 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 8 THEN 2 WHEN "- Open Date"."Day in Week" = 5 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 9 THEN 3 WHEN "- Open Date"."Day in Week" = 5 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 15 THEN 4 WHEN "- Open Date"."Day in Week" = 6 
    		AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    		AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 6 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" = 6 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 7 THEN 2 WHEN "- Open Date"."Day in Week" = 6 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 8 THEN 3 WHEN "- Open Date"."Day in Week" = 6 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 14 THEN 4 WHEN "- Open Date"."Day in Week" = 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" BETWEEN -1 
    		AND 0 THEN 0 WHEN "- Open Date"."Day in Week" = 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 1 THEN 1 WHEN "- Open Date"."Day in Week" <= 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 76 THEN 2 WHEN "- Open Date"."Day in Week" = 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 7 THEN 3 WHEN "- Open Date"."Day in Week" = 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 13 THEN 4 WHEN "- Open Date"."Day in Week" = 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" = 14 THEN 5 WHEN "- Open Date"."Day in Week" = 7 
    		AND "Help Desk Attributes"."TAT To Close - Days" <= 20 THEN 6 ELSE 0 
    		END)) <= 10 THEN 1 ELSE 0 
    END)
    

    Still quite WTF tho ;)

    Bored much?????????????

    A simple replace AND by \nAND did the trick quite neatly ;)

  • (cs)

    @ Quietust: Your indenting is a lot better yeh, I kinda gave up trying to fix it all halfway through it :S

  • Anonymous Coward (unregistered) in reply to StarLite

    Please explain to me how proper indentation made that suck less? ;-)

  • frustrati (unregistered) in reply to Vollhorst
    Vollhorst:
    Reminds me of the only valid way to validate email addresses with regular expressions:
    That, in turn, reminded me of the slightly less WTFery regexp for validating UK post codes:

    (GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})

    Yes, UK post codes suck. "GIR 0AA" is a historic post code that is valid, although it does not follow the slightly more structured rules for the remaining codes.

  • frustrati (unregistered) in reply to AJ
    AJ:
    I worked for a subprime lender for about 5 years, and the actual approval code looks more like this:

    public static bool ApproveLoan() { return Borrower.HasPulse; }

    Sure? My guess would have been:

    public static bool ApproveLoan() { return Borrower != null; }

  • His (unregistered) in reply to Vollhorst
    Vollhorst:
    Reminds me of the only valid way to validate email addresses with regular expressions:

    Hej, it is impossible to check for a valid email address with RegEx. Email addresses may contain multiple comments in brackets which can't be checked by a regular grammar (Chomsky-3 type). You need at least a context free grammar for that (Chomsky-2, e.g. BNF).

  • (cs) in reply to frustrati
    frustrati:
    AJ:
    I worked for a subprime lender for about 5 years, and the actual approval code looks more like this:

    public static bool ApproveLoan() { return Borrower.HasPulse; }

    Sure? My guess would have been:

    public static bool ApproveLoan() { return Borrower != null; }

    No, the !HasPulse cases require the SecretIllegalOverride() method.

  • (cs)

    You are in a maze twisty of predicates, all different.

  • Ryan (unregistered) in reply to Vollhorst

    I think I just died a little inside.

  • (cs) in reply to poopdeville
    poopdeville:
    That's not the only valid way. Consider a regexp A. If A matches against valid emails, so does A.{0}. By induction, there are infinitely many valid regular expressions to accept the grammar of emails.
    Nice induction, but it rather rests on the lemma that the original regexp A matches against valid emails. Which, AFAIR, it does not.

    Why anybody would want to do this with a regexp (see Jon, above), if indeed at all, in the first place is an exercise left for the reader.

  • Benie (unregistered) in reply to erlando

    I remember looking up some example SQL code a few days back and saw a 4 like query with 4 aggrigate functions and could count business days between any 2 dates. Although, it didn't keep track of holidays. Best part is it was small enough to memorize and type down in ~10 seconds.

  • kl (unregistered) in reply to Vollhorst

    Sorry, this regex is incomplete - it doesn't allow for comments, which have to be removed in preprocessing step. (yes, you can put a friggin comment anywher inside your e-mail address).

  • steamed about taxis (unregistered) in reply to Vollhorst
    Vollhorst:
    Reminds me of the only valid way to validate email addresses with regular expressions:

    (?:(?:\r\n)?[ \t])(?:(?:(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?: \r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t])))@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\0 31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)
    ](?:(?:\r\n)?[ \t])
    )(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+ (?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?: (?:\r\n)?[ \t])))|(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n) ?[ \t]))<(?:(?:\r\n)?[ \t])(?:@(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:
    r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n) ?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t] )))(?:,@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])* )(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))) :(?:(?:\r\n)?[ \t]))?(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+ |\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r \n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?: \r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t ]))"(?:(?:\r\n)?[ \t])))@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031 ]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)]( ?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(? :(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(? :\r\n)?[ \t])))>(?:(?:\r\n)?[ \t]))|(?:[^()<>@,;:\".[] \000-\031]+(?:(? :(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)? [ \t]))"(?:(?:\r\n)?[ \t])):(?:(?:\r\n)?[ \t])(?:(?:(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]| \.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<> @,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|" (?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t])))@(?:(?:\r\n)?[ \t] )(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\ ".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(? :[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[ ]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))|(?:[^()<>@,;:\".[] \000- \031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|( ?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]))<(?:(?:\r\n)?[ \t])(?:@(?:[^()<>@,; :\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([ ^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\" .[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[
    ]\r\]|\.)](?:(?:\r\n)?[ \t])))(?:,@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".
    [] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]
    r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\] |\.)](?:(?:\r\n)?[ \t])))):(?:(?:\r\n)?[ \t]))?(?:[^()<>@,;:\".[] \0 00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(?:[^"\r\]|\ .|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[^()<>@, ;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[]]))|"(? :[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t])))@(?:(?:\r\n)?[ \t]) (?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\". []]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t])(?:[ ^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[] ]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))>(?:(?:\r\n)?[ \t]))(?:,\s( ?:(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\ ".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]))(?:.(?:( ?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[ ["()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t ])))@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t ])+|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(? :.(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+| \Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))|(?: [^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\".[
    ]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]))<(?:(?:\r\n) ?[ \t])(?:@(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[[" ()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n) ?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<> @,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))(?:,@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@, ;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:.(?:(?:\r\n)?[ \t] )(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\ ".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))):(?:(?:\r\n)?[ \t]))? (?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[["()<>@,;:\". []]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]))(?:.(?:(?: \r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[[ "()<>@,;:\".[]]))|"(?:[^"\r\]|\.|(?:(?:\r\n)?[ \t]))"(?:(?:\r\n)?[ \t]) ))@(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t]) +|\Z|(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t]))(?:
    .(?:(?:\r\n)?[ \t])(?:[^()<>@,;:\".[] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[["()<>@,;:\".[]]))|[([^[]\r\]|\.)](?:(?:\r\n)?[ \t])))>(?:( ?:\r\n)?[ \t]))))?;\s*)

    and last time I checked the O'Reilly book that has this regex, they state that it still isn't 100% for matching valid email address patterns (no regex will tell you if the account behind the address is legit).

  • Jesus (unregistered) in reply to Vollhorst

    the missed a semi-colon

  • Mat (unregistered) in reply to Vollhorst

    That is not "the only way". That is a relatively famous computer-generated regular expression that mostly matches a string if and only if it is a valid email address.

    (?:[a-z0-9!#$%&'+/=?^_{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])

    Should match RFC 2822 compliant email addresses, though it wont validate the domain name or even the TLD. Its a very different but equally valid solution to the problem.

  • Jeff (unregistered) in reply to erlando
    erlando:
    I will now go dig holes for a living for the rest of my life.

    To coin a phrase, WTF? You mean there's more to coding than digging holes? NOW he tells me, thirty years on!

    Oh. You mean dirt holes, not schedule or budget holes. Sowwee.

  • Number A. (unregistered)

    WTF!!!

    1. Count the number of open Help Desk tickets
    2. Create an in-memory table that can be JOINed against later
    3. Give Michael L. migraines
    4. Counts off business days between two dates
    5. Make you want to commit suicide

    and you're answering F, E...????

    I can't see it clearly... maybe 5??

  • John Glenn (unregistered)

    I challenge you to a game of trivia! Click here to battle against me online at ConQUIZtador. Let's see who's the winner... https://conquiztador.com/?a=26041

Leave a comment on “Pop Quiz, Hotshot”

Log In or post as a guest

Replying to comment #:

« Return to Article