SQL Server - How to eliminate spaces when table is converted from excel

Asked By Partha Chakraborty
07-Dec-06 02:01 AM

Hi,

I have converted an excel sheet in to my database table. But the problem is when I am trying to find out some values it is not giving proper result. I am using LTRIM and RTRIM but it is not working. Because during the conversion some characters are included in the fields that cannot be eliminated by the TRIM functions (but they look like blank). Any solution!!!!!!

Please help.

Partha

sol  sol

07-Dec-06 02:12 AM

Hi Partha,

               Can you try and convert the excel sheet to a CSV file first and see if it is just the spaces that are there or any other characters are appearing (open the CSV in notepad)? Usually this sort of problem does not happen when excel sheet is imported as a table so as you have suggested above there must be some other charcters in there. 

Also, you can try and run an update query on the table that just trims the data in the columns and then try to find the length of some data, in case it is different than what you expect I would suggest you retype the values in a new sheet (and import in the DB) just to test them out. 

Hope this helps.

Tab character  Tab character

07-Dec-06 02:45 AM
See whether you have a Tab character - Char(9) inside those fields which appears as space to you

Find and Replace  Find and Replace

07-Dec-06 09:39 AM

As pointed out by Venkatesh, it is possible that those characters are tab characters.  Aside from tab characters, they may be carriage returns or line feeds.  To verify, you can run the following query:

SELECT * FROM YourTable WHERE YourColumn LIKE '%' + CHAR(9) + '%'

SELECT * FROM YourTable WHERE YourColumn LIKE '%' + CHAR(13) + '%'

If these queries return values, you can easily replace them with an empty string as follows:

UPDATE YourTable
SET YourColumn = REPLACE(YourColumn, CHAR(9), '')

UPDATE YourTable
SET YourColumn = REPLACE(YourColumn, CHAR(13), '')

http://www.sql-server-helper.com

Create New Account
help
Insert NULL into Char column? SQL Server SQL Server 2005 and 2008: I have a table with a column defined as Char. The table contains a dozen rows where the Char column contains a NULL value when viewed thru SQL Server Management Studio. If I insert a new row, passing Nothing to the Char column
text datatype in new SQL Server SQL Server I read in help that the text datatype is going away. Does anyone know what Or do you know where there is an article that may describe an alertnative? Thanks. SQL Server Programming Discussions SQL Server (1) Varchar (1) Text (1) Varbinary (1) Nvarchar (1) Table (1) Ntext (1) Image (1
Setting SQL Server 2005 to default newly created DBs ect. to D: instead of C: SQL Server SQL Server 2005 was installed on C:. . We want to make sure all new DBs get created under D: \ Data What's the best approach for this? SQL Server Programming Discussions SQL Server 2005 (1) CREATE DATABASE (1) Trigger (1) Exec (1) MyFirstDatabase (1
SQL 2008 PowerShell and SQL 2000 SQL Server Hi, SQL 2008 Books Online says that "SQL Server PowerShell can connect to instances of SQL Server 2008, SQL Server 2005, or SQL Server 2000. . . earliest version of SQL Server 2000
IN Clause works in Oracle, not Sql Server SQL Server Hi, The following SQL works in Oracle 9, but not SQL Server 2005. Does anyone know of a similar syntax in SQL Server without using an OR clause ? SELECT * FROM idxcst_his WHERE (gvkey, iid) IN (('006066', '01