Remove First and Last character of TableColumn in SQL Server 2008

In this article I am going to explain how to remove the first and last character from a table column in SQL Server 2008.
  • 5227

Introduction

In this article I will explain various queries to remove the first and last character of a table column in SQL Server 2008. We can remove the characters from simple values of table column. There are various queries explained below to remove first and last character from a table column. So let's take a practical example of how to remove the first and last character from a table column in SQL Server 2008.

Example

Create a table named Employee with columns (ID, F_Name, L_Name, Salary, Region, City). The tables is shown in below image.

 Table.jpg

1. Remove first character from a table column F_Name of Employee Table, type following statement:

select F_Name, RIGHT (F_Name, len (F_Name) -1) as AfterRemovalOfFirstCharacter from Employee

Now execute above statement.

OUTPUT:

Remove_FirstCharacter-from-tableColumn.jpg

2. Remove last character from a table column F_Name of Employee Table, type following statement:

select F_Name, LEFT (F_Name, len (F_Name) -1) as AfterRemovalOfLastCharacter from Employee

Now execute above statement.

OUTPUT:

Remove_LastCharacter-from-tableColumn.jpg

3. Remove first and  last character from a table column F_Name of Employee Table, type following statement:

select F_Name, LEFT (RIGHT (F_Name, len (F_Name)-1),len(F_Name)-2)as RemovalOfFiratAndLastCharacter from Employee

Now execute above statement.

OUTPUT:

RemoveFirstAndLastCharacter-from-tablecolumn.jpg


© 2019 DotNetHeaven. All rights reserved.