Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 REVERSE (Transact-SQL)

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Other versions are also available for the following:
SQL Server 2008 Books Online (June 2009)
REVERSE (Transact-SQL)

Returns the reverse of a string value.

Topic link icon Transact-SQL Syntax Conventions

REVERSE ( string_expression )
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;
GO
SELECT FirstName, REVERSE(FirstName) AS Reverse
FROM Person.Contact
WHERE ContactID < 5
ORDER BY FirstName;
GO

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 ;
GO

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 ;
GO
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker