Remove Characters in MSSQL record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpeacock
    New Member
    • Apr 2007
    • 17

    Remove Characters in MSSQL record

    Is there a way to basically trim off the last X characters in a field?

    Example

    Field 1 Value - 15000
    Field 2 Value - 2645678

    Desired output - 15
    Desired output - 2645

    Can I perform a trim or something to remove the last 3 or X number of characters?

    I know that I can RTRIM for spaces, but I wanted to trim the actual characters.

    Thanks in advance!
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Try this:

    [PHP]
    select substring(cast( 2645678 as varchar(20)), 1, len(cast(264567 8 as varchar(20))) - 3)[/PHP]

    Good Luck

    Comment

    • rharvieuxsql
      New Member
      • Nov 2006
      • 9

      #3
      --Try this

      select LEFT (your_column, LEN(your_column )-3) from your_table

      Comment

      Working...