--- description: "REVERSE (Transact-SQL)" title: "REVERSE (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "03/13/2017" ms.prod: sql ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.reviewer: "" ms.technology: t-sql ms.topic: reference f1_keywords: - "REVERSE_TSQL" - "REVERSE" dev_langs: - "TSQL" helpviewer_keywords: - "expressions [SQL Server], reverse" - "REVERSE function" - "reverse character expressions" ms.assetid: 555d8877-7cc7-4955-ae2c-6215aca313b7 author: julieMSFT ms.author: jrasnick monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # REVERSE (Transact-SQL) [!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)] Returns the reverse order of a string value. ![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) ## Syntax ```syntaxsql REVERSE ( string_expression ) ``` [!INCLUDE[sql-server-tsql-previous-offline-documentation](../../includes/sql-server-tsql-previous-offline-documentation.md)] ## Arguments *string_expression* *string_expression* is an [expression](../../t-sql/language-elements/expressions-transact-sql.md) of a string or binary data type. *string_expression* can be a constant, variable, or column of either character or binary data. ## Return Types **varchar** or **nvarchar** ## Remarks *string_expression* must be of a data type that is implicitly convertible to **varchar**. Otherwise, use [CAST](../../t-sql/functions/cast-and-convert-transact-sql.md) to explicitly convert *string_expression*. ## Supplementary Characters (Surrogate Pairs) When using SC collations, the REVERSE function will not reverse the order of two halves of a surrogate pair. ## Examples The following example returns all contact first names with the characters reversed. This example uses the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database. ```sql SELECT FirstName, REVERSE(FirstName) AS Reverse FROM Person.Person WHERE BusinessEntityID < 5 ORDER BY FirstName; GO ``` [!INCLUDE[ssResult](../../includes/ssresult-md.md)] ``` FirstName Reverse -------------- -------------- Ken neK Rob boR Roberto otreboR Terri irreT (4 row(s) affected) ``` The following example reverses the characters in a variable. ```sql 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 **varchar** data type and then reverses the result. ```sql SELECT REVERSE(1234) AS Reversed ; GO ``` ## Examples: [!INCLUDE[ssSDWfull](../../includes/sssdwfull-md.md)] and [!INCLUDE[ssPDW](../../includes/sspdw-md.md)] The following example returns names of all databases, and the names with the characters reversed. ```sql SELECT name, REVERSE(name) FROM sys.databases; GO ``` ## See Also [CONCAT (Transact-SQL)](../../t-sql/functions/concat-transact-sql.md) [CONCAT_WS (Transact-SQL)](../../t-sql/functions/concat-ws-transact-sql.md) [FORMATMESSAGE (Transact-SQL)](../../t-sql/functions/formatmessage-transact-sql.md) [QUOTENAME (Transact-SQL)](../../t-sql/functions/quotename-transact-sql.md) [REPLACE (Transact-SQL)](../../t-sql/functions/replace-transact-sql.md) [STRING_AGG (Transact-SQL)](../../t-sql/functions/string-agg-transact-sql.md) [STRING_ESCAPE (Transact-SQL)](../../t-sql/functions/string-escape-transact-sql.md) [STUFF (Transact-SQL)](../../t-sql/functions/stuff-transact-sql.md) [TRANSLATE (Transact-SQL)](../../t-sql/functions/translate-transact-sql.md) [CAST and CONVERT (Transact-SQL)](../../t-sql/functions/cast-and-convert-transact-sql.md) [Data Types (Transact-SQL)](../../t-sql/data-types/data-types-transact-sql.md) [String Functions (Transact-SQL)](../../t-sql/functions/string-functions-transact-sql.md)