Program to find if a digit is Palindrome or not in TSQL

Rajnilari2015
Posted by Rajnilari2015 under Sql Server category on | Points: 40 | Views : 397
DECLARE @Number INT = 111

;WITH getDigitsCTE AS (
SELECT
SlNo = 1
, Quotient = @Number / 10
,Remainder = @Number % 10

UNION ALL

SELECT
SlNo = SlNo + 1
,Quotient / 10
, Quotient % 10

FROM getDigitsCTE

WHERE Quotient > 0
)
SELECT
IsPalindrome = IIF(OriginalNumber = ReversedNumber,'PALINDROME','NOT PALINDROME')
FROM
(SELECT
OriginalNumber=@Number
,ReversedNumber =
STUFF((SELECT '' +
dw.Remainder + ' '
FROM getDigitsCTE dw
ORDER BY dw.SlNo
FOR XML PATH('')),1,0,''))X


/*

IsPalindrome
---------------
PALINDROME

*/

Comments or Responses

Login to post response