Remove First and Last character of String in SQL Server 2008
In this article I am going to explain how to remove the first and last character from a string in SQL Server 2008.
Introduction
In this article I will explain various queries to remove the first and last character of a string in SQL server 2008. We can remove the characters from simple string or from a column values of a given table. There are various queries explained below to remove first and last character from a string.
1. Remove first character from a string
To remove first character from a string named "Microsoft", type following query. And result should be like "icrosoft".
Select 'Microsoft' as BeforeRemovalOfFirstCharacter, right ('Microsoft', len ('Microsoft')-1) as FirstCharacterRemoved
|
Now execute above statement and see output. Fist character i.e: "M" is removed from "Microsoft".
OUTPUT:
2. Remove last character from a string
To remove last character from a string named "Microsoft", type following query. And result should be like "Microsof".
Select 'Microsoft' as BeforeRemovalOfLastCharacter, left ('Microsoft', len ('Microsoft')-1) as AfterRemoveLastCharacter
|
Now execute above statement and see output.
OUTPUT:
3. Remove first and last character from string
To remove first and last character from a string named "Microsoft", type following query. And result should be like "icrosof".
select 'Microsoft' as string, left (right ('Microsoft', len ('Microsoft')-1), len ('Microsoft')-2) as AfterRemovalFirstAndLastCharacter;
|
OUTPUT: