Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

SQL REVERSE Function

by suresh

The SQL REVERSE is one of the SQL String Function, which is used to reverse the specified expression.

In this article we will show you, How to write String REVERSE Function with an example.

Sql Server REVERSE Function Syntax

The basic syntax of the SQL Server REVERSE Function is as shown below:

SELECT REVERSE (String_Expression)
FROM [Source]

We are going to use the below shown data to explain the 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.

T-SQL CODE

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'

OUTPUT

SQL REVERSE FUNCTION 1

ANALYSIS

Within this reverse function example query, the below lines of code is used to declare string variable and assigning the string data.

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

In the below statement, We used REVERSE function to reverse the string variable @String_Expression. We also assigned new name to that result using ALIAS Column.

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'

SQL REVERSE Function Example 2

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

T-SQL CODE

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

OUTPUT
SQL REVERSE FUNCTION 2

Thank You for Visiting Our Blog

Placed Under: SQL

Stay in Touch!

Sign Up to receive Email updates on Latest Tutorials

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy