Tuesday, April 4, 2017

How to reverse a string in MS-Sql Server without using REVERSE() function

How to reverse a string in MS-Sql Server without using REVERSE( ) function

    Its simple ,Try following query  
its one of the interview question in these days

DECLARE @Str VARCHAR (50)='MS SQL'
DECLARE @Result VARCHAR (50)=''
DECLARE @Len INT

SET @Len=LEN (@Str)
               
           WHILE (0<@Len)
           BEGIN
                 SET @Result=@Result+SUBSTRING (@Str,@Len,1)
                 SET @Len=@Len-1
          END

PRINT @Result



OUT PUT :




No comments:

Post a Comment

Comments system

Disqus Shortname

How To Print Star Triangle In SQL Server Using REPLICATE( ) Function

Print * Triangle In SQL Server Using REPLICATE( ) Function   In SQL Server we can print * triangle in many methods.One of the simple m...