[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 30343
  • Last Modified:

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
0
zintech
Asked:
zintech
  • 2
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
DECLARE @INPUT VARCHAR(20)
SET @INPUT = 'RAJKUMAR'
SELECT SUBSTRING(@INPUT, 2, LEN(@INPUT))

-- AJKUMAR

Open in new window

0
 
Rajkumar GsSoftware EngineerCommented:
Same - another example
DECLARE @INPUT VARCHAR(100)
SET @INPUT = 'www.experts-exchange.com'
SELECT SUBSTRING(@INPUT, 2, LEN(@INPUT))
-- ww.experts-exchange.com

Open in new window

0
 
CluskittCommented:
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.
0
 
NorieCommented:
Do you mean the 2nd last character in the string?

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

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now