trim all field values in a table

Posted on 2006-05-02
Last Modified: 2012-08-14
I have a table with several fields. I am trying to trim the spacing in the values in each field.

I know that I can trim a value in a field but how to trim the whole field.

Question by:trknssr
    LVL 50

    Accepted Solution

    give an example of your before and after data?



    or if you mean you have internal spaces...

    then Ltrim(RTRIM(REPLACE(YourColumn,'  ',' ')))

    will replace multiple internal spaces with just a single space...

    LVL 44

    Expert Comment

    Hi trknssr,

    you can do an update for each column like

    update mytable
    set myfield1 = LTRIM(RTRIM(myfield1))), myfield2=LTRIM(RTRIM(myfield2))

    hope this helps a bit
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    if you have field that are defined as CHAR(x), you should rather define the m into VARCHAR(x)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now