SQL Server has in build function REVERSE to reverse string. A T-SQL example is given below

1_Reverse string in SQL server

The function is very much direct. It takes an input string and returns the reversed string.

Another solution to reverse a string without using REVERSE function is given below

The above function is an inline table valued function which uses tally table to reverse the input string. The logic is pretty simple. The statement SUBSTRING(@string,Nums.numer,1) breaks the string into rows of alphabets and then the string is concatenated in descending order.   The output of the function is given below.

2_Reverse string in SQL server


Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

Follow me on TwitterFollow me on FaceBook