Home » SQL SERVER REVERSE

SQL SERVER REVERSE

SQL Server REVERSE function is a string function that returns the reverse order of a string value. It returns a value of type varchar or nvarchar .





SYNTAX

REVERSE(input_string )

input_string
input_string can be a constant, variable, or column of either character or binary data.

Lets look at an example of REVERSE() Function in SQL Server.

The following statement implicit conversion from an int data type into varchar data type and then reverses the input string and returns result.

SELECT REVERSE(123456789) AS Reversed;

The following statement reverses the characters in a variable.

DECLARE @string varchar(9); 
SET @string = 'microsfot'; 
SELECT REVERSE(@string) AS Reversed ;

The following statement returns the reverse value for Age column  in a table.

 SELECT Age , REVERSE(Age) AS AgeReversed FROM Person

SQL Server String Functions



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.