SQLTeam.com | Weblogs | Forums

Data problem (select)


I have a data problem:

I have a table that has two columns:

col1 (int)
col2 (nvarchar (255))

col1 col2


data tables that were imported from an Excel file and fueled by my application

I have a problem reading certain data (not all)


select * from mytable Where col2 like 'TUNISIA%': it works
select * from mytable Where col2 like 'TUNISIA%': it does not work
select * from mytable Where col2 like 'TUNISIA t%': it does not work

The problem is in the space character

what do I have to do?

thank you


Check that it is really a SPACE or other unprintable character

Or use CLEAN() in excel to remove any before you import in.


how to know the character?

According to the display is a space

I even tried the ASCII code (255 alt), still nothing

The problem is that it's been that I imported data from EXCEL (myself) but I have not received this complaint from my client now

are there a way to see the hidden character?


use SUBSTRING() to extract 1 character and then use ASCII() to view the ascii code


I found the character, code 32

I wrote this query and it works

UPDATE mytable SET col2= REPLACE(col2, ' ', ' ')

(code 32
thank you khtan


ASCII 32 is SPACE and your replace statement basically replace space with space.


Use TRIM functions to ignore spaces while selecting. Such as
select * from mytable Where LTRIM(RTRIM(col2)) like 'TUNISIA%'