September 5, 2017 at 12:29 pm
hi ,
i hvave a value something like this column scrapetype "WebCrawler.Crawlable.EURRUSSIA.C_Darty ". My join is on this column and it does not appear because guessing of spaces. how can we remove it? I tried replace,ltrim and rtrim it doe snot work.
CREATE TABLE #temp
( iD INT identity(1,1)
,CODE Varchar(20)
,Crawler Nvarchar(200)
,Pricetype varchar(20)
)
INSERT into #temp values('DARTY','WebCrawler.Crawlable.EURRUSSIA.C_Darty ','ASP')
September 5, 2017 at 12:52 pm
You could use REPLACE(), but there are no spaces in that string to begin with.
DECLARE @TextWithSpaces VARCHAR(100) = 'I have a whole lot of spaces';
PRINT REPLACE(@TextWithSpaces,' ','');
September 5, 2017 at 12:59 pm
"WebCrawler.Crawlable.EURRUSSIA.C_Darty "
"WebCrawler.Crawlable.EURRUSSIA.C_Darty"
This is how it shows in the table and length differes as 32 and 31. i tried replace , ltrim , rtrim .It is not working.
September 5, 2017 at 1:16 pm
komal145 - Tuesday, September 5, 2017 12:59 PM"WebCrawler.Crawlable.EURRUSSIA.C_Darty "
"WebCrawler.Crawlable.EURRUSSIA.C_Darty"This is how it shows in the table and length differes as 32 and 31. i tried replace , ltrim , rtrim .It is not working.
My best guess is that it's another white space character such as a tab, carriage return, or line feed. You can also find out which by selecting ASCII(RIGHT(Crawler)).
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 5, 2017 at 1:26 pm
komal145 - Tuesday, September 5, 2017 12:29 PMhi ,
i hvave a value something like this column scrapetype "WebCrawler.Crawlable.EURRUSSIA.C_Darty ". My join is on this column and it does not appear because guessing of spaces. how can we remove it? I tried replace,ltrim and rtrim it doe snot work.
CREATE TABLE #temp
( iD INT identity(1,1)
,CODE Varchar(20)
,Crawler Nvarchar(200)
,Pricetype varchar(20)
)
INSERT into #temp values('DARTY','WebCrawler.Crawlable.EURRUSSIA.C_Darty ','ASP')
Post your real code because trailing spaces aren't normally considered during character based joins. There's something else going on here.
Also, if REPLACE isn't killing the spaces, then that's not a space in the data. Chances are pretty good that it's CHAR(140), which is a "non-breakable hard space". Use ASCII(RIGHT(datacolumhere,1) to find out what it is.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 6, 2017 at 7:35 am
Jeff Moden - Tuesday, September 5, 2017 1:26 PMPost your real code because trailing spaces aren't normally considered during character based joins. There's something else going on here.
Also, if REPLACE isn't killing the spaces, then that's not a space in the data. Chances are pretty good that it's CHAR(140), which is a "non-breakable hard space". Use ASCII(RIGHT(datacolumhere,1) to find out what it is.
Char(160) is the non-breakable space.
Thomas Rushton
blog: https://thelonedba.wordpress.com
September 6, 2017 at 9:09 am
Try this code (adapt it to your table) to find out what the problematic character is.
WITH
E(n) AS(
SELECT n FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))E(n)
),
E2(n) AS(
SELECT a.n FROM E a, E b
),
E4(n) AS(
SELECT a.n FROM E2 a, E2 b
),
cteTally(n) AS(
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) n
FROM E4
)
SELECT e.Crawler, SUBSTRING(e.Crawler, a.n, 1), ASCII(SUBSTRING(e.Crawler, a.n, 1))
FROM cteTally a
JOIN #temp e ON a.n <= LEN(e.Crawler)
September 6, 2017 at 12:23 pm
ThomasRushton - Wednesday, September 6, 2017 7:35 AMJeff Moden - Tuesday, September 5, 2017 1:26 PMPost your real code because trailing spaces aren't normally considered during character based joins. There's something else going on here.
Also, if REPLACE isn't killing the spaces, then that's not a space in the data. Chances are pretty good that it's CHAR(140), which is a "non-breakable hard space". Use ASCII(RIGHT(datacolumhere,1) to find out what it is.
Char(160) is the non-breakable space.
You're absolutely correct. Thank you for the correction.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 13, 2017 at 11:07 am
komal145 - Tuesday, September 5, 2017 12:29 PMhi ,
i hvave a value something like this column scrapetype "WebCrawler.Crawlable.EURRUSSIA.C_Darty ". My join is on this column and it does not appear because guessing of spaces. how can we remove it? I tried replace,ltrim and rtrim it doe snot work.
CREATE TABLE #temp
( iD INT identity(1,1)
,CODE Varchar(20)
,Crawler Nvarchar(200)
,Pricetype varchar(20)
)
INSERT into #temp values('DARTY','WebCrawler.Crawlable.EURRUSSIA.C_Darty ','ASP')
select LTRIM(RTRIM(column)) from table;
You can use above Ltrim and Rtrim to remove preceding and leading spaces
September 13, 2017 at 11:29 am
komal145 - Tuesday, September 5, 2017 12:29 PMhi ,
i hvave a value something like this column scrapetype "WebCrawler.Crawlable.EURRUSSIA.C_Darty ". My join is on this column and it does not appear because guessing of spaces. how can we remove it? I tried replace,ltrim and rtrim it doe snot work.
CREATE TABLE #temp
( iD INT identity(1,1)
,CODE Varchar(20)
,Crawler Nvarchar(200)
,Pricetype varchar(20)
)
INSERT into #temp values('DARTY','WebCrawler.Crawlable.EURRUSSIA.C_Darty ','ASP')
select LTRIM(RTRIM(column)) from table;
You can use above Ltrim and Rtrim to remove preceding and leading spaces
If you had actually bothered to read the post that you quoted, you would see that he already tried that and it didn't work.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 13, 2017 at 12:10 pm
As drew said, you are likely dealing with a non-space whitespace character; what Luis posted will help you identify what that character is.
This can easily be resolved using patexclude8K like so:
-- some text with a tab at the end (which will look like a space in SSMS)
declare @txt varchar(100) = '"WebCrawler.Crawlable.EURRUSSIA.C_Darty'+char(9)+'"';
print @txt; -- note the output
--solution: return any text that is not alphabetical a space, quote, dot or underscore.
select newString from dbo.patExclude8K(@txt, '[^a-zA-Z"._]');
-- Itzik Ben-Gan 2001
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply