Sql Server : Check string is Palindrome or not - ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Sql Server : Check string is Palindrome or not

In this article I am going to explain how to check string is Palindrome or not using Reverse function or without reverse function in sql server.

I want to check given text/string is Palindrome or not. Simplest way to check is using reverse function.
* Palindrome means word that reads same forward as backward.

 Check Palindrome using Reverse function:

declare @palindromestring varchar(200) ='Level'
select @palindromestring as [Text],REVERSE(@palindromestring) as [Reverse Text],case when
@palindromestring=REVERSE(@palindromestring) then 'Yes' else 'No' END AS Palindrome

Check Palindrome without reverse function:

DECLARE @palindromestring VARCHAR(100) ='Level'
;with revcte AS
SELECT CAST('' AS VARCHAR(100)) AS reversestr,LEN(@palindromestring) AS ln
SELECT CAST(reversestr+SUBSTRING(@palindromestring,ln,1) AS VARCHAR(100)) AS reversestr,
ln-1 AS ln FROM revcte WHERE ln>=1
SELECT @palindromestring as [Text], reversestr as [Reverse Text] FROM revcte WHERE ln=0

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.