SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Too Many Spaces Between Words
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 3

Kristen
Test

United Kingdom
22403 Posts

Posted - 02/17/2006 :  13:24:48  Show Profile  Reply with Quote
I'm connecting to my Tally table to find the first "sensible" character that does not appear in string itself.

SELECT TOP 1 @charMarker = CHAR(MyNumberColumn)
FROM	dbo.MyTallyTable
WHERE	    MyNumberColumn >= 33	-- Normal AlphaNumericPunctuation range
	AND MyNumberColumn <= 127
	AND CHARINDEX(CHAR(MyNumberColumn), @strData) = 0

but it does need consideration of the collation issues ...

Kristen
Go to Top of Page

Seventhnight
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 02/17/2006 :  13:56:39  Show Profile  Visit Seventhnight's Homepage  Reply with Quote
hey Arnold - how about these Þ (alt-0222) and ð (alt-0240)

here is an alternate that uses 4 replaces and 2 uniqes...


declare @CHR		varchar(2)
declare @UNIQ		varchar(2)
Set @CHR = 'b'
Set @UNIQ = 'Þð' (0222,0240)

Select 
	data,
	replace(data,replicate(@CHR,2),@UNIQ),
	replace(replace(data,replicate(@CHR,2),@UNIQ),reverse(@UNIQ),''),
	replace(replace(replace(data,replicate(@CHR,2),@UNIQ),reverse(@UNIQ),''),@UNIQ,@CHR),
	replace(replace(replace(replace(data,replicate(@CHR,2),@UNIQ),reverse(@UNIQ),''),@UNIQ,@CHR),replicate(@CHR,2),@CHR)
From
	(
	Select data='abba' Union All
	Select 'abbba' Union All
	Select 'abbbba' Union All
	Select 'abbbbba' Union All
	Select 'abbbbbba' Union All
	Select 'abbbbbbba' Union All
	Select 'abbbbbbbba'
	) a


Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 02/17/2006 :  15:59:19  Show Profile  Reply with Quote
quote:
Originally posted by Kristen
...but it does need consideration of the collation issues ...



I started wondering about this whole exercise for that very reason.

These work OK for something like spaces, where case does not matter, but do you really know if is OK to relace Hhhhhhhh with h or H?

There are lots of issues besides the technical to deal with when you try to generalize it.









CODO ERGO SUM
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 02/17/2006 :  21:34:25  Show Profile  Reply with Quote
"There are lots of issues besides the technical to deal with when you try to generalize it."

Yeah, bummer isn't it

Maybe a "flag character" in the range 0-31 is collation-insensitive? (Now there's a new term! )

Kristen
Go to Top of Page

gongxia649
So Suave

Azores
344 Posts

Posted - 09/27/2006 :  09:07:13  Show Profile  Visit gongxia649's Homepage  Reply with Quote
quote:
Originally posted by Seventhnight

do you actually care how many spaces there are... or do you just want to force there to be just one?

if its the latter... a series of 3 replaces will do the trick...

I usually use (in SQL)

Replace(Replace(Replace(myCol,' ',' þ'),'þ ',''),'þ','')

so in access it should be

Replace(Replace(Replace(myCol," "," þ"),"þ ",""),"þ","")



Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."




what is this character "þ"?
Go to Top of Page

gongxia649
So Suave

Azores
344 Posts

Posted - 09/27/2006 :  09:09:53  Show Profile  Visit gongxia649's Homepage  Reply with Quote
quote:
Originally posted by X002548

Maybe something like


DECLARE @x varchar(8000)
SELECT @x = 'Brett  J   Kaiser'
SELECT REPLACE(REPLACE(@x,'  ',' '),'  ',' ')




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx





how wil you do it with 100 fields.?
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 09/27/2006 :  09:13:47  Show Profile  Reply with Quote
>>what is this character "þ"?
It represents what a hermaphrodite does when they drink a lot of fluids....sorry



Be One with the Optimizer
TG
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 09/27/2006 :  13:31:51  Show Profile  Reply with Quote
"what is this character "þ"?"

See Arnold Fribble's comment earlier in the thread - Posted - 10/16/2005 : 11:21:38

and Arnold's comments later in the thread that clarify further.

Kristen
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

USA
7020 Posts

Posted - 09/27/2006 :  21:16:34  Show Profile  Reply with Quote
quote:
Originally posted by gongxia649
...what is this character "þ"?



It's very useful for dealing with thorny problems.





CODO ERGO SUM
Go to Top of Page

heberd
Starting Member

1 Posts

Posted - 05/14/2010 :  08:49:40  Show Profile  Reply with Quote
look at http://sqltrim.codeplex.com for a universal function
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000