SQL REVERSE Function

The SQL REVERSE is one of the String Functions used to reverse the specified expression. The syntax of the SQL Server REVERSE Function is

SELECT REVERSE (String_Expression)
FROM [Source]

We are going to use the below-shown data to explain the string REVERSE Function

SQL REVERSE FUNCTION

SQL REVERSE Function Example 1

The REVERSE function is used to reverse the given string. The following query will show multiple ways to use this String REVERSE Function.

DECLARE @String_Expression varchar(50)
SET @String_Expression = 'SQL Server'

SELECT REVERSE (@String_Expression) AS 'SQLReverse' 

--String Reverse directly
SELECT REVERSE ('SQL Server 2014') AS 'SQL Reverse'
SQL REVERSE FUNCTION 1

Within this reverse function query, declared a string variable and assigning the string data.

DECLARE @String_Expression varchar(50)
SET @String_Expression = 'SQL Server'

We used the REVERSE String Function to reverse the string variable @String_Expression

SELECT REVERSE (@String_Expression) AS 'SQL Reverse'

In the next line, we used the REVERSE Function directly on the string.

--String Reverse directly
SELECT REVERSE ('SQL Server 2014') AS 'SQL Reverse'

String REVERSE Function Example 2

The REVERSE function also allows you to reverse the expressions inside the columns. In this SQLServer example, We are going to reverse all the records in [Department Name] column present in the Employe table.

SELECT [FirstName]
      ,[LastName]
      ,[DepartmentName]
      ,REVERSE ([DepartmentName]) AS [SQL Reverse]
 FROM [Employe]

SQL REVERSE FUNCTION 2