0

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 characters from the left? I would like to see:

005953

Edit my value is:

SELECT LEN(TABLE.VALUE)-3)
PriceCheaperton
  • 5,071
  • 17
  • 52
  • 94
  • 1
    possible duplicate of [Fastest way to remove non-numeric characters from a VARCHAR in SQL Server](http://stackoverflow.com/questions/106206/fastest-way-to-remove-non-numeric-characters-from-a-varchar-in-sql-server) – Meff May 29 '13 at 13:58

5 Answers5

3
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
Community
  • 1
  • 1
zimdanen
  • 5,508
  • 7
  • 44
  • 89
2

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.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
1
SELECT RIGHT('ABC0005953', LEN('ABC0005953') - 3)
Meff
  • 5,889
  • 27
  • 36
0

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

Sultan
  • 53
  • 1
  • 9
0

Two options for you:

SELECT SUBSTRING('ABC0005953', 5,7)

SELECT RIGHT('ABC0005953', (LEN('ABC0005953') - 4))
CatchingMonkey
  • 1,391
  • 2
  • 14
  • 36