Ask Your Question
3

How do I delete the final character from a string using T-SQL?

asked 2023-06-24 03:37:42 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-24 03:47:01 +0000

ladyg gravatar image

You can use the LEFT function to retrieve all but the final character of a string. For example, if your string variable is @str, you can delete the final character using the following code:

SET @str = LEFT(@str, LEN(@str) - 1)

This sets @str to a substring of itself, starting at the first character and ending at the second-to-last character, effectively removing the final character.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-24 03:37:42 +0000

Seen: 12 times

Last updated: Jun 24 '23