Link to home
Start Free TrialLog in
Avatar of zintech
zintech

asked on

SQL Substring to end of string

I would like to do a SUBSTRING statement in SQL that gives me the result of the 2nd character position to the end of the string.  However when I try to execute the statement

SELECT SUBSTRING (field1, 2)

It throws an error and places a comma after the "2" like it expects another parameter
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

DECLARE @INPUT VARCHAR(20)
SET @INPUT = 'RAJKUMAR'
SELECT SUBSTRING(@INPUT, 2, LEN(@INPUT))

-- AJKUMAR

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It need a parameter of length (how many chars you want to show). In theory, the best practice would be LEN-1, but you can just overload it and it will return till the end.
Avatar of Norie
Norie

Do you mean the 2nd last character in the string?

SELECT LEFT(RIGHT('TheString',2),1)