How to use REVERSE in Sql Server



SQL Server provides the REVERSE function to invert the order of the characters in a string. In this article, we will learn how to use REVERSE in SQL Server.

The Syntax

The basic syntax of a REVERSE is as follows:

SELECT REVERSE(string_name);
  • string is the string to reverse

Getting Setup

For this, we will be using docker. This is recommended for more than just using SQL Server. To find how to install docker go here:

Now create a file called docker-compose.yml and add the following.

version: "3.9"
    image: ""
      - 1433:1433
        SA_PASSWORD: "Your_password123"
        ACCEPT_EULA: "Y"

Open a terminal and go to the folder the file is located. Then run the following.

docker-compose up

If you are looking for another good reference, you can check here:

A Simple Example

The reverse function is pretty straight forward, we simply reverse any varchar type. Here is the example.

SELECT reverse('hello world') as res;
dlrow olleh