MS SQL Server REVERSE() Function

Sometimes you may need to work with specific part of a expression in MS SQL Server. There is a function called REVERSE in MS SQL Server by which you can do this. REVERSE function returns the reverse order of a string value.

Let’s see the function syntax:

REVERSE(string_expression);

In this syntax:

  • In this function there are only one parameter.
  • Parameter string_expression string_expression is an expression of a string or binary data type. string_expression can be a constant, variable, or column of either character or binary data.
  • Parameter string_expression must be of a data type that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert string_expression.
  • Function returns data type of varchar or nvarchar.
  • Function returns the reverse order of a string value.

The following example uses REVERSE function to reverse of a specific string.

DECLARE @name varchar(30) = 'Minhajur Rahman Khan';
SELECT @name AS original_name,REVERSE(@name) AS reverse_name; 

Here is the result set.

original_name reverse_name
Minhajur Rahman Khan nahK namhaR rujahniM

I have an another post MS SQL Server String Related Functions where you will learn about different string related functions of MS SQL Server.

In this tutorial, I have shown you how to use REVERSE function in MS SQL Server. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.

Add a Comment