trim values from left using SQL

后端 未结 5 1861
忘了有多久
忘了有多久 2021-01-28 02:44

I want to trim the characters from the left in my SQL value:

I have the following value:

ABC0005953

How do i trim the value 3 character

相关标签:
5条回答
  • 2021-01-28 03:10
    SELECT RIGHT('ABC0005953', LEN('ABC0005953') - 3)
    
    0 讨论(0)
  • 2021-01-28 03:10

    Perhaps you could could just use right(x, len(x)-3)

    0 讨论(0)
  • 2021-01-28 03:12

    Two options for you:

    SELECT SUBSTRING('ABC0005953', 5,7)
    
    SELECT RIGHT('ABC0005953', (LEN('ABC0005953') - 4))
    
    0 讨论(0)
  • 2021-01-28 03:14
    SELECT SUBSTRING('ABC0005953', 4, LEN('ABC0005953'))
    

    Start at the fourth character and keep going.

    (Just posting as an alternative to the RIGHT(...) solution.)

    In response to your update, I assume you mean you want to apply the above to your table:

    SELECT SUBSTRING(TABLE.VALUE, 4, LEN(TABLE.VALUE))
    FROM TABLE
    

    From your other question:

    I have the following:

    SELECT DISTINCT

    Left(GIFTHEADER.pID + GIFTHEADER.PID + '-' + Cast(PAYMENTDETAIL.PLINENO as Varchar),18)

    AS TRANSACTIONREF...

    Currently my value looks like this:

    ABC0005953ABC0005953

    I want to simply strip off the first 4 characters from GIFTHEADER.pID

    If you want to remove the first four characters from GIFTHEADER.pID, I would recommend removing them before putting the value into your combined string:

    SELECT DISTINCT
        LEFT(SUBSTRING(GIFTHEADER.pID, 5, LEN(GIFTHEADER.pID) +
            GIFTHEADER.PID +
            '-' +
            Cast(PAYMENTDETAIL.PLINENO as Varchar),18)
        AS TRANSACTIONREF
    
    0 讨论(0)
  • 2021-01-28 03:27

    You can use STUFF function to replace chars 1 thru 3 with an empty string

    SELECT STUFF('ABC0005953',1,3,'')
    

    I believe it's a better and more universal approach than cutting string.

    0 讨论(0)
提交回复
热议问题