Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

REVERSE (Transact-SQL)

Returns the reverse of a string value.

Topic link iconTransact-SQL Syntax Conventions

REVERSE (string_expression )


string_expression is an expression of a string or binary data type. string_expression can be a constant, variable, or column of either character or binary data.

varchar or nvarchar

string_expression must be of a data type that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert string_expression.

The following example returns all contact first names with the characters reversed.

USE AdventureWorks;
SELECT FirstName, REVERSE(FirstName) AS Reverse
FROM Person.Contact
WHERE ContactID < 5
ORDER BY FirstName;

Here is the result set.

FirstName      Reverse
-------------- --------------
Catherine      enirehtaC
Gustavo        ovatsuG
Humberto       otrebmuH
Kim            miK
(4 row(s) affected)

The following example reverses the characters in a variable.

DECLARE @myvar varchar(10)
SET @myvar = 'sdrawkcaB'
SELECT REVERSE(@myvar) AS Reversed ;

The following example makes an implicit conversion from an int data type into varch data type and then reverses the result.

SELECT REVERSE(1234) AS Reversed ;

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft