The SQL Server REVERSE is one of the String Functions used to reverse the specified expression, and its syntax 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 Example
The REVERSE function is used to invert the given string. The following query will show multiple ways to use it.
We first declared a string variable within this query and assigned the string data. Next, we used the String method to reverse the string variable @String_Expression. In the next line, we used it directly on the string.
DECLARE @String_Expression varchar(50) SET @String_Expression = 'SQL Server' SELECT REVERSE (@String_Expression) AS 'SQLReverse' --directly SELECT REVERSE ('SQL Server 2014') AS 'SQLReverse'
The reverse function also allows you to reverse the expressions inside the columns. In this Server example, We are going to reverse all the records in the [Department Name] column present in the Employee table.
SELECT [FirstName] ,[LastName] ,[DepartmentName] ,REVERSE ([DepartmentName]) AS [SQLReverse] FROM [Employe]