Introduction:
In this article I will explain how to remove first or last characters from string in SQL server.
In this article I will explain how to remove first or last characters from string in SQL server.
Description:
In
previous post I explained concatenate row values into string and substring function example to replace particular of string in
SQL Server and many articles relating to SQL
Server.
Now I will explain how to write a query to remove first or last character from
string in SQL Server. Here I will explain with one example for that I have one string
which contains data like this
Here I want to remove first character from string
and need to get remaining string values for that we need to write a query like as
show below
Syntax
to Remove First character
from string
SELECT SUBSTRING(ColumnName,2,(LEN(ColumnName))) FROM TABLENAME
|
Ex:
DECLARE @name NVARCHAR(MAX)
SET @name=',SureshDasari,MaheshD,MadhavS,PrasanthiD'
SELECT Substring(@name, 2, (len(@name))) as UserNames
|
OutPut
Syntax
to Remove Last character from string
If
we want to remove last character from
string we need to write query like as shown below
SELECT SUBSTRING(ColumnName,1,(LEN(ColumnName)-1)) FROM TABLENAME
|
Ex:
DECLARE @name NVARCHAR(MAX)
SET @name='SureshDasari,MaheshD,MadhavS,PrasanthiD,'
SELECT Substring(@name, 1, (len(@name)-1)) as UserNames
|
OutPut
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
4 comments :
All ur post are so useful to me ...
Thanks a lot for valuable example..
Regards,
Nishant Giri
declare @sample varchar(30)
set @sample=',siva,'
select substring(substring(@sample,2,len(@sample)),1,len(substring(@sample,2,len(@sample)))-1)
Thanks for this valuable example
Note: Only a member of this blog may post a comment.