Click here to Skip to main content

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Happy new year... kind of... Pinmemberhoernchenmeister28-Jan-13 23:49 
JokeRe: Happy new year... kind of... PinmemberVUnreal8-Feb-13 11:27 
GeneralJust got an error from VS2012 PinmemberBrisingr Aerowing15-Jan-13 9:48 
GeneralGetting it wrong badly PinmemberPIEBALDconsult9-Jan-13 15:12 
GeneralRe: Getting it wrong badly PinmemberSentenryu10-Jan-13 7:31 
GeneralRe: Getting it wrong badly PinmemberPIEBALDconsult10-Jan-13 8:42 
GeneralRe: Getting it wrong badly PinmemberSentenryu10-Jan-13 23:31 
GeneralRe: Getting it wrong badly PinprotectorAspDotNetDev10-Jan-13 8:37 
PIEBALDconsult wrote:
PATINDEX doesn't allow a parameter to tell it where to start so it always starts over from the beginning

 
Not only that, but the repeated use of stuff creates the same kind of inefficiency as you'd see in C# with the repeated use of "+" to concatenate strings. There is no StringBuilder in SQL, but there are workarounds. If you really want performance, this is what I'd do (describing rather than writing out, because I'm lazy)...
 
Create a while loop to visit each character in the string. Perform PATINDEX only on single characters (or two-character sequences, if you like). Output the strings to a local table variable then combine them using the FOR XML PATH technique (I haven't tried it myself, but it seems like it'd avoid repeat concatenations).

GeneralRe: Getting it wrong badly PinmemberPIEBALDconsult10-Jan-13 8:52 
GeneralRe: Getting it wrong badly PinprotectorAspDotNetDev10-Jan-13 9:11 
GeneralFacepalm Moment PinmemberZac Greve7-Jan-13 9:47 
GeneralRe: Facepalm Moment PinmemberPJ Arends7-Jan-13 10:03 
GeneralRe: Facepalm Moment PinmemberZac Greve7-Jan-13 10:06 
GeneralRe: Facepalm Moment Pinmemberpeterchen7-Jan-13 11:03 
GeneralRe: Facepalm Moment PinmemberZac Greve7-Jan-13 11:12 
GeneralRe: Facepalm Moment PinmvpDave Kreskowiak7-Jan-13 10:15 
GeneralRe: Facepalm Moment PinmemberZac Greve7-Jan-13 10:30 
GeneralRe: Facepalm Moment PinmemberBobJanova8-Jan-13 0:29 
GeneralRe: Facepalm Moment PinmemberPIEBALDconsult7-Jan-13 10:17 
GeneralRe: Facepalm Moment Pinmemberlewax007-Jan-13 11:52 
GeneralRe: Facepalm Moment PinmemberJörgen Andersson7-Jan-13 11:05 
GeneralRe: Facepalm Moment PinprotectorPete O'Hanlon7-Jan-13 11:17 
GeneralRe: Facepalm Moment PinmemberZac Greve7-Jan-13 11:20 
GeneralRe: Facepalm Moment PinmemberRick Sparks7-Jan-13 15:17 
GeneralMessage Other user using CodeProject PinmemberSuvabrata Roy26-Dec-12 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 26 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid