-----判断是否是一元二次方程
declare @a int,@b int,@c int,@x1 decimal(18,2),@x2 decimal(18,2)
set @a=1
set @b=5
set @c=4
if @a=0
begin
print '不是一元二次方程,因为a=0'
end
else
begin
declare @sqrt decimal(18,2)
set @sqrt=@b*@b-4*@a*@c
if @sqrt<0
begin
print '此方程无解,因为sqrt小于0'
end
else if @sqrt=0
begin
set @x1 = (-@b+SQRT(@sqrt))/(2*@a)
print '有两个相等的根,结果为'+cast(@x1 as varchar(20))
end
else
begin
set @x1 = (-@b+SQRT(@sqrt))/(2*@a)
set @x2 = (-@b-SQRT(@sqrt))/(2*@a)
print '有两个不相等的根,结果为x1='+cast(@x1 as varchar(20))+'x2='+cast(@x2 as varchar(20))
end
end