Friday , July 19 2024

How To Delete the Last Character of a String in TSQL(DATALENGTH and LEFT Functions)

When developing code in TSQL, we may need to delete the last character of a string in some cases.

The other day, I used the “,” brace to combine the strings in a column. At the end, a value was generated as follows. The article name is: “How To Concatenate Query Results in SQL Server(TSQL)

That’s why I had to delete the last character of all data in the column.


We are creating a table as follows and we are adding a few records to this table.

When we read the data from the table, we see that the last characters are “,” as you see below.

With the help of the following script, in order to test the script, we read the data whose last characters have been deleted.

After making sure that the script is correct, we delete the last character of the data in the column with the help of the following script.


About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *