• sqlserver12345 (10/18/2013)


    declare @count int

    declare @charvaluefront varchar

    declare @charvalueback varchar

    declare @frontpos int

    declare @backpos int

    select @count=len('ABC')

    set @frontpos=1

    set @backpos=@count

    while(@frontpos<=@count)

    begin

    select @charvaluefront=substring('ABC',@frontpos,1)

    select @charvalueback=substring('ABC',@backpos,1)

    set @frontpos=@frontpos+1

    set @backpos=@backpos-1

    print @charvaluefront

    print @charvalueback

    end

    How do I compare @charvaluefront and @charvalueback values to test if the values are equal and print that its a palindrome.

    I tried the if clause but it does not work.Any suggestions please

    Ok, the more I think about this and the "No REVERSE" requirement, the more I think this is homework and the instructor wants you to use WHILE loops. Are you being required to use a WHILE loop or not because, in real life, I wouldn't go anywhere near a WHILE loop for this. Of course, in real life, I'd be using a REVERSE after I cleaned the string.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)