how to use trim??

  • I didn´t get how tu use trim function.

    I have a col with data and i need to erase all blank spaces to the right of the string.

    thanks in advance.

  • There isn't a "trim" function in T-SQL. There are "LTrim" and "RTrim". One takes spaces off of the left side, the other takes them off of the right side.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • igngua (12/4/2009)


    I didn´t get how tu use trim function.

    I have a col with data and i need to erase all blank spaces to the right of the string.

    thanks in advance.

    Did you read Books Online ?

    If you have spaces on right of the column, then use RTRIM.

    SELECT RTRIM(column) FROM table

    This is only a simple select statement, you can use TRIM functions while updating or inserting also.


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • Bru Medishetty (12/4/2009)


    igngua (12/4/2009)


    I didn´t get how tu use trim function.

    I have a col with data and i need to erase all blank spaces to the right of the string.

    thanks in advance.

    Did you read Books Online ?

    If you have spaces on right of the column, then use RTRIM.

    SELECT RTRIM(column) FROM table

    This is only a simple select statement, you can use TRIM functions while updating or inserting also.

    Also - keep in mind that you need to take into account the data type of what you are trying to trim, and the ANSI_PADDING setting at the time.

    http://technet.microsoft.com/en-us/library/ms187403.aspx

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • There is no TRIM() function in SQL Server, although you could argue there should be, for times when you need it.

    You can always create your own udf which basically does this for you (performs a LTRIM(RTRIM([Column])) which can then be called in your code. Its something I've considered putting in the MODEL database before now but not got around to implementing.

  • puliiiiiiiiiii

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply