SQL Server REVERSE() Function

The REVERSE() function in SQL Server flips the order of characters in a string. It's a simple yet useful string manipulation function.



REVERSE(): Definition and Usage

REVERSE() takes a string as input and returns a new string with the characters in the opposite order. This can be handy for various text processing tasks, such as creating reversed strings for specific purposes or simply reversing the order of characters for display or analysis.

Syntax

Syntax

REVERSE(string)
      

Parameter Values

Parameter Description
string The string you want to reverse. This is required.

Examples

Reversing a Literal String

This example reverses the string "SQL Tutorial".

Syntax

SELECT REVERSE('SQL Tutorial');
      
Output

lairotuT LQS
      

Reversing Strings from a Column

This example reverses the 'CustomerName' for each customer in the 'Customers' table (assuming a table named 'Customers' with a 'CustomerName' column exists).

Syntax

SELECT REVERSE(CustomerName)
FROM Customers;
      
Output

(Reversed CustomerNames from the Customers table)
      

**Note:** The second example's output will depend on the data present in your `Customers` table. Each `CustomerName` will be displayed in reverse order.