SQL Server > Conversion related

Get a part of string from a sentence in SQL Server

How to get a part of string from a sentence in SQL Server?

To get part of string from a sentence, we can use SUBSTRING function. It accepts three parameter

  • First parameter is the string to get substring from
  • Second parameter is the length of characters from where to start getting the string
  • Third parameter is the total length of characters we need to get starting from 2nd parameter value.
DECLARE @myName varchar(50)
SET @myName = 'SN ITFunda Services LLP'

SELECT @myName, SUBSTRING(@myName, 4, LEN(@myName)),
              SUBSTRING(@myName, 12, LEN(@myName))

The first column will give us the complete string, the second will give us all the string starting from 4th position, the third column will give us string starting from 12th position in the whole string.

 Views: 1105 | Post Order: 82

Write for us