|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 7:30 PM
Points: 20,093,
Visits: 13,643
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 9:44 AM
Points: 1,321,
Visits: 3,215
|
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 7:30 PM
Points: 20,093,
Visits: 13,643
|
|
Thanks Adi... it's an old solution and it's not mine. I've just never seen anyone explain it before and thought an explanation was long overdue especially since it's been coming up a lot on the forums, again. A lot of the "answer" posts have included a substantial amount of RBAR and, of course, that drove me to write the article.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 9:07 AM
Points: 428,
Visits: 872
|
|
Another (very good) example of something that initially appears to be a horrendous problem having an elegant and relatively simple solution.
Must add to briefcase
Normal chaos will be resumed as soon as possible.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, March 03, 2010 5:28 AM
Points: 2,155,
Visits: 1,676
|
|
Nice one jeff.
"Keep Trying"
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 18, 2010 1:40 AM
Points: 166,
Visits: 404
|
|
Hi Does this simple replace not work then?
REPLACE(@SomeText, ' ',' ') which is actually :
REPLACE(@SomeText, '[space][space]','[space]') i.e. replace two spaces with one..
This seams to work fine for me, but I could well be missing something?
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, February 23, 2010 2:35 PM
Points: 487,
Visits: 619
|
|
Jeff
Nice article - I just hope that when I *finally* get round to writing mine then it's anywhere near one tenth as good as yours generally are...
M
My home page
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Yesterday @ 6:26 AM
Points: 91,
Visits: 157
|
|
Richard Briggs (11/16/2009)
Hi Does this simple replace not work then? REPLACE(@SomeText, ' ',' ') which is actually : REPLACE(@SomeText, '[space][space]','[space]') i.e. replace two spaces with one.. This seams to work fine for me, but I could well be missing something?
sure, it works. if you only have 2 spaces it will work. the problem on the article however is for when u have a random amount of spaces. with your example you would have to manually add a REPLACE for each extra space
-- Thiago Dantas
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 18, 2010 1:40 AM
Points: 166,
Visits: 404
|
|
I think you need to try this out ... the above comment (sorry dant12) is not correct:
It looks like the following will replace up to six spaces
REPLACE(@SomeText, ' ',' ') And the following will sort the rest out :
REPLACE(REPLACE(@SomeText, ' ',' '),' ',' ') try this one :
DECLARE @sample VARCHAR(1000) SET @sample= 'ALKSDKLKJ LSJD ASD LSD S D DJD D D D D D D'
SELECT REPLACE(REPLACE(@sample,' ',' '),' ',' ')
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, February 18, 2010 1:40 AM
Points: 166,
Visits: 404
|
|
Actually typo in posted code, the second REPLACE is also restricted to 6 spaces, I wonder why?
Cheers
|
|
|
|