January 13, 2014 at 4:49 pm
Hi Guys
I have imported some data into two tables from a messy spreadsheet provided by my client.
I realise now that a lot of the fields have a leading space and would like to trim them on the whole table.
Can someone give me a nudge here?
Thanks in advance!
January 13, 2014 at 5:05 pm
You might need to do an update on all fields.
Something like this:
UPDATE MyTable
SET column1 = LTRIM(column1),
column2 = LTRIM(column2),
column3 = LTRIM(column3),
--...
columnN = LTRIM(columnN)
January 13, 2014 at 5:16 pm
Thnk you luiz
Worked like a charm.
I am also trying to copy data from one column to the other and get the following error
Here is the statement
update stkitem
SET Csimplecode=Code
and the error is
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
Any ideas?
January 13, 2014 at 5:24 pm
That's because your column Code is larger than your column Csimplecode.
If you provide DDL of your table, I could give you the exact code, but you basically need to use a LEFT(Code, N) where N is the length of your Csimplecode column (You will lose data).
January 13, 2014 at 5:30 pm
Thanks Luis
Code column is (Varchar(400),Null)
Csimplecode Column is (Varchar(20),Null)
However none of the data is longer than 20 Characters
Your help is appreciated.
A
January 13, 2014 at 8:23 pm
I would want to check first before possibly truncating data:
select max(len(code)) from stkitem
or
select *
from stkitem
where len(code) > 20
If you do try:
update stkitem
SET Csimplecode=left(Code,20)
Here is the link for MS: http://technet.microsoft.com/en-us/library/ms177601.aspx
Mike
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply