3 Ways to Find the Position of a Substring within a String in MySQL

MySQL has a number of string functions that return the position of a substring within a string. More specifically, they return the position of the first occurrence within the string (or the first occurrence after a given starting point).

The functions I’m referring to are as follows:

  • INSTR()
  • LOCATE()
  • POSITION()

Below is an overview of each one.

Continue reading

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