sqlserver12345 (10/18/2013)
declare @count intdeclare @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
Change is inevitable... Change for the better is not.