Site icon Database Tutorials

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.

Example:

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.

Exit mobile version