REVERSE(SUBSTRING(wtf))



  • My current favorite stored procedure in our code base.



    SELECT WBSID, REVERSE(SUBSTRING(REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6), <br>
    				PATINDEX('%[^.]%', REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6)), 25)) + ' | ' + description AS MasterWBS <br>
    FROM WBSMasterTbl<br>
    WHERE Display = 'True'<br>
    ORDER BY MasterWBS<br>


  • Moments like that are when I put my hands on the desk, push myself back, and don my thousand-mile stare all the way to the coffee machine and back.



  • @theflin said:

    My current favorite stored procedure in our code base.



    SELECT WBSID, REVERSE(SUBSTRING(REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6), <br>
    				PATINDEX('%[^.]%', REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6)), 25)) + ' | ' + description AS MasterWBS <br>
    FROM WBSMasterTbl<br>
    <b>WHERE Display = 'True'</b><br>
    ORDER BY MasterWBS<br></blockquote>
    

    People can be mislead by the reverse part but behind the section in bold lies something far more dangerous.



  • Its not a Real WTF unless it also has an SQL injection vulnerability, and ulness that WHERE clause looked like this one-

    WHERE odered = 'True' OR odered = 'TRUE' OR odered = 'true'



  • @SamC said:

    Its not a Real WTF unless it also has an SQL injection vulnerability, and ulness that WHERE clause looked like this one-

    WHERE odered = 'True' OR odered = 'TRUE' OR odered = 'true'

    Depending on the collation, testing for case may be useless. Also I have no idea where that "odered" comes from, unles it's from Dyslexialand.



  • @SamC said:

    Its not a Real WTF unless it also has an SQL injection vulnerability, and ulness that WHERE clause looked like this one-

    WHERE odored = 'True' OR odored = 'TRUE' OR odored = 'true'

    FTFY



  • @dhromed said:

    Moments like that are when I put my hands on the desk, push myself back, and don my thousand-mile stare all the way to the coffee machine and back.
    That's a serious distance to go for just a bit of coffee. Can't they move it a bit closer; say, in the next state?

     



  • @theflin said:

    My current favorite stored procedure in our code base.



    SELECT WBSID, REVERSE(SUBSTRING(REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6), <br>
    				PATINDEX('%[^.]%', REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6)), 25)) + ' | ' + description AS MasterWBS <br>
    FROM WBSMasterTbl<br>
    WHERE Display = 'True'<br>
    ORDER BY MasterWBS<br></blockquote>&nbsp;</p><p mce_keep="true">To me it looks like a fine way to do string maching from the right of the string. One thing that SQL servers doesn't seem to be too good at out of the box.</p><p mce_keep="true">Reverse the string and reverse the search pattern and Bob's your uncle.</p><p mce_keep="true">Otherwise: What Ronald said.</p>


  • @Severity One said:

    @dhromed said:

    Moments like that are when I put my hands on the desk, push myself back, and don my thousand-mile stare all the way to the coffee machine and back.
    That's a serious distance to go for just a bit of coffee. Can't they move it a bit closer; say, in the next state?

     

    You should go to your local VA watering hole. You could pick up a female soldier that will let you do just about anything plus if she's back from one of the wars she'll possibly have that thousand-mile stare which you will then understand.



  • @Severity One said:

    @dhromed said:

    Moments like that are when I put my hands on the desk, push myself back, and don my thousand-mile stare all the way to the coffee machine and back.
    That's a serious distance to go for just a bit of coffee. Can't they move it a bit closer; say, in the next state?

     

    See other thread about crossing state lines with beverages.



  • @Ronald said:

    yet another lolpussy threadshit

    You think you're funny but you're not.

    Grow the fuck up.



  • @dsckeld said:

    @theflin said:

    My current favorite stored procedure in our code base.



    SELECT WBSID, REVERSE(SUBSTRING(REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6), <br>
    				PATINDEX('%[^.]%', REVERSE(level1 + '.' + level2 + '.' + level3 + '.' + <br>
    				level4 + '.' + level5 + '.' + level6)), 25)) + ' | ' + description AS MasterWBS <br>
    FROM WBSMasterTbl<br>
    WHERE Display = 'True'<br>
    ORDER BY MasterWBS<br></blockquote>&nbsp;</p><p>To me it looks like a fine way to do string maching from the right of the string. One thing that SQL servers doesn't seem to be too good at out of the box.</p><p>Reverse the string and reverse the search pattern and Bob's your uncle.</p><p>Otherwise: What Ronald said.</p></blockquote>
    

    The real WTF is people claiming this is not a WTF.

    What it seems to do (to me) is to remove trailing periods. Basically, if say level 4, 5 and 6 are empty, the concatenated string would become l1.l2.l3..., and this magic would fix it to be "l1.l2.l3". Even if this should, in some odd cases, be a good requirement (having a hardcoded 6 level depth as maximum), can't you, say:

    - Use some RTRIM function (not sure if whatever SQL this is has it)?

    - Simply concatenate some conditionals that are empty when levelX is empty, and ".levelX" if not?

    - Take a substring with as length the index of pattern '%[.]*$%'?

    Edit: Just googling for a bit for RTRIM-ing none-spaces in MSSQL brought me to this page. See the second post and compare ;-): http://stackoverflow.com/questions/7838676/sql-server-trim-character



  •  Actually it looks like a slightly more complex way of doing Subtring(string, len - 25, len).
    I.E. It's getting the last 25 characters of the string "level1 + '.' + level2 + '.' + level3 + '.' + level4 + '.' + level5 + '.' + level6"



  • @Ronald said:

    Depending on the collation, testing for case
    may be useless.
     

    Of course it's useless. What do you think this is, The Daily Best Code?

    If I recall correctly, the collation (for everything; literally every column but the primary key was a varchar) was latin1_ci. Which is a WTF in itself.

    @Ronald said:

    Also I have no idea where that "odered" comes from,
    unles it's from Dyslexialand.
     

    A produck is odered when a cusomer completes the ckekout process after adding their itoms to the shooping cart.



  • @flabdablet said:

    @Ronald said:
    yet another lolpussy threadshit

    You think you're funny but you're not.

    Grow the fuck up.

    I'm not sure what is a "lolpussy threadshit" but as funny goes even reading the phonebook is funnier than you pretending to be a bitter moron with bad manners. Once in a while I even wonder if you're pretending.



  • @SamC said:

    A produck is odered when a cusomer completes the ckekout process after adding their itoms to the shooping cart.

    Is that your Arnold Shwarzenneger impression?



  • @SamC said:

    the shooping cart.

    Shoop da woop, the Photoshop of horrors...

     



  • @Ronald said:

    but as funny goes even reading the phonebook is funnier than you pretending to be a bitter moron with bad manners.
     

    I'd rather play Creative Mode.



  • @dhromed said:

    @Ronald said:

    but as funny goes even reading the phonebook is funnier than you pretending to be a bitter moron with bad manners.
     

    I'd rather play Creative Mode.

    I'd take a dramatic reading of the phonebook over Minecraft any day.



  • @Ben L. said:

    I'd take a dramatic reading of the phonebook over Minecraft any day.
     

    Perhaps just for the curiosity factor.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.