DECLARE @StringToReverse VARCHAR(55)
SET @StringToReverse = 'jagdish kholiya'
;WITH cte AS (
SELECT @StringToReverse AS string, CAST('' AS VARCHAR(55)) AS revStr, LEN(@StringToReverse) AS ln
UNION ALL
SELECT SUBSTRING(string,0,ln) AS string, CAST(revStr + SUBSTRING(string,ln,1) AS VARCHAR(55)) AS revStr, ln-1 AS ln
FROM cte
WHERE ln >= 1)
SELECT @StringToReverse AS String, revStr FROM cte WHERE ln = 0
SET @StringToReverse = 'jagdish kholiya'
;WITH cte AS (
SELECT @StringToReverse AS string, CAST('' AS VARCHAR(55)) AS revStr, LEN(@StringToReverse) AS ln
UNION ALL
SELECT SUBSTRING(string,0,ln) AS string, CAST(revStr + SUBSTRING(string,ln,1) AS VARCHAR(55)) AS revStr, ln-1 AS ln
FROM cte
WHERE ln >= 1)
SELECT @StringToReverse AS String, revStr FROM cte WHERE ln = 0
No comments:
Post a Comment