-3

Below query which insert records to the Table does not trim the empty space.

Insert into MyTable (MyColumn)
select RTRIM(LTRIM(rowvalue)) from #temptable

Alternatively, if i assign to a variable and insert back, empty spaces are trimmed.

Declare @var varchar(max)
set @var = (    select RTRIM(LTRIM(rowvalue)) from #temptable  )
go
Insert into MyTable (MyColumn) values ( @var)

Instead of assigning, is there a way to trim the empty spaces in the Insert query.

goofyui
  • 3,362
  • 20
  • 72
  • 128

1 Answers1

0

It may be that you have high ASCII characters in the field. Try this and see if the result comes back, it checks whether the field has characters between 1-31 and 127-255.

-- See if it's in the low ASCII range
SELECT *      
FROM #temp      
WHERE rowvalue LIKE '%[' + CHAR(1)+ '-' +CHAR(31)+']%'  COLLATE Latin1_General_100_BIN2

-- See if it's in the high ASCII range
SELECT *      
FROM #temp      
WHERE rowvalue LIKE '%[' + CHAR(127)+ '-' +CHAR(255)+']%'  COLLATE Latin1_General_100_BIN2

If the record comes back you may need to replace the character in order to remove it. See here

Element Zero
  • 1,651
  • 3
  • 13
  • 31