DECLARE @STR VARCHAR(50)='BABJI'
DECLARE @LEN INT
DECLARE @A INT=0
DECLARE @Q VARCHAR(30)=''
SELECT @LEN=LEN(@STR)
WHILE(@A<=@LEN)
BEGIN
SELECT @Q=@Q+SUBSTRING(@STR,LEN(@STR)-@A,1)
SET @A=@A+1
END
PRINT( @Q)
OUTPUT : IJBAB
BY USING STORED PROCEDURE TO GET PALINDROME FORM:
CREATE PROC USP_PALINDOM(@STR VARCHAR(30))
AS
BEGIN
DECLARE @LEN INT
DECLARE @A INT=0
DECLARE @Q VARCHAR(30)=''
SELECT @LEN=LEN(@STR)
WHILE(@A<=@LEN)
BEGIN
SELECT @Q=@Q+SUBSTRING(@STR,LEN(@STR)-@A,1)
SET @A=@A+1
END
PRINT( @Q)
END
EXEC USP_PALINDROME @SRT='BABJI'
OUTPUT: IJBAB
NOTE: By using string function REVERSE (@STR) to get the palindrom form.
SELECT REVERSE('BABJI')
OUTPUT: IJBAB
GIVEN STRING IS PLINDROM OR NOT:
CREATE PROC USP_PALINDOM(@STR VARCHAR(30))
AS
BEGIN
DECLARE @LEN INT
DECLARE @A INT=0
DECLARE @Q VARCHAR(30)=''
SELECT @LEN=LEN(@STR)
WHILE(@A<=@LEN)
BEGIN
SELECT @Q=@Q+SUBSTRING(@STR,LEN(@STR)-@A,1)
SET @A=@A+1
END
PRINT( @Q)
IF(@Q=@STR)
BEGIN
PRINT 'PALINDROME'
PRINT 'THANK YOU'
END
ELSE
PRINT 'NOT A PALINDROME'
PRINT 'THANK YOU'
END
EXEC USP_PALINDROME @SRT='BABJI'
OUTPUT: IJBAB
NOT A PALINDROME
THANK YOU
EXEC USP_PALINDROME @SRT='MADAM'
OUTPUT: MADAM
PALINDROME
THANK YOU
DECLARE @LEN INT
DECLARE @A INT=0
DECLARE @Q VARCHAR(30)=''
SELECT @LEN=LEN(@STR)
WHILE(@A<=@LEN)
BEGIN
SELECT @Q=@Q+SUBSTRING(@STR,LEN(@STR)-@A,1)
SET @A=@A+1
END
PRINT( @Q)
OUTPUT : IJBAB
BY USING STORED PROCEDURE TO GET PALINDROME FORM:
CREATE PROC USP_PALINDOM(@STR VARCHAR(30))
AS
BEGIN
DECLARE @LEN INT
DECLARE @A INT=0
DECLARE @Q VARCHAR(30)=''
SELECT @LEN=LEN(@STR)
WHILE(@A<=@LEN)
BEGIN
SELECT @Q=@Q+SUBSTRING(@STR,LEN(@STR)-@A,1)
SET @A=@A+1
END
PRINT( @Q)
END
EXEC USP_PALINDROME @SRT='BABJI'
OUTPUT: IJBAB
NOTE: By using string function REVERSE (@STR) to get the palindrom form.
SELECT REVERSE('BABJI')
OUTPUT: IJBAB
GIVEN STRING IS PLINDROM OR NOT:
CREATE PROC USP_PALINDOM(@STR VARCHAR(30))
AS
BEGIN
DECLARE @LEN INT
DECLARE @A INT=0
DECLARE @Q VARCHAR(30)=''
SELECT @LEN=LEN(@STR)
WHILE(@A<=@LEN)
BEGIN
SELECT @Q=@Q+SUBSTRING(@STR,LEN(@STR)-@A,1)
SET @A=@A+1
END
PRINT( @Q)
IF(@Q=@STR)
BEGIN
PRINT 'PALINDROME'
PRINT 'THANK YOU'
END
ELSE
PRINT 'NOT A PALINDROME'
PRINT 'THANK YOU'
END
EXEC USP_PALINDROME @SRT='BABJI'
OUTPUT: IJBAB
NOT A PALINDROME
THANK YOU
EXEC USP_PALINDROME @SRT='MADAM'
OUTPUT: MADAM
PALINDROME
THANK YOU
No comments:
Post a Comment