MSSQL求100-999的水仙花数
代码
--author:【DBA】小七
--datatime: 2010-1-20 16:52:00
--title:100-999的水仙花数
--水仙花数:如果三位数的个位的三次方加十位的三次方加上百位的三次方之和为其本身,那么这个数就为水仙花数
declare @a int
set @a=100;
while @a<=999
BEGIN
if power(substring(cast(@a as char(3)),1,1),3)+
power(substring(cast(@a as char(3)),2,1),3)+
power(substring(cast(@a as char(3)),3,1),3)=@a
begin
print @a
end
set @a=@a+1
end