How to Return the ASCII Code Value for a given Character in SQL Server

If you ever need to find the ASCII code for a given character when using SQL Server, the T-SQL ASCII() function is probably what you need.

The ASCII() function returns the ASCII code value of the leftmost character of a character expression. Simply provide the character as an argument and SQL Server will return the ASCII value of that character (or the leftmost character in the string).

Continue reading

SQL Server REPLACE() vs TRANSLATE(): What are the Differences?

Starting with SQL Server 2017, you can now use the T-SQL TRANSLATE() function to translate one or more characters into another set of characters.

At first glance, you might think that the TRANSLATE() function does exactly the same thing as the REPLACE() function, but there are significant differences between the two.

Continue reading

How to Select a Certain Number of Characters from the Left or Right of a String in SQL Server

If you ever find yourself wanting only the first part of a string, or the last part of it, this article might help.

This article is specific to SQL Server, but the functionality is pretty common across most/all database management systems, not to mention most programming languages.

When working with SQL Server, you can use theT-SQL LEFT() and RIGHT() functions to return any given number of characters from the left or right of a string.

Continue reading

How to Return the Left or Right Part of a String in MySQL

When working with MySQL databases, you might occasionally find yourself needing to select only a certain number of characters from the left or right of a string. In such cases, you can use the LEFT() and RIGHT() functions to do just that.

Here’s the syntax for both of these functions:

LEFT(str,len)
RIGHT(str,len)

Where str is the string that contains the substring you need to return, and len is the number of characters from the left you want returned.

Continue reading