存储过程声明错误

时间:2013-05-16 08:22:37

标签: sql sql-server-2005 stored-procedures

我是存储过程的新手。

我在一个变量中取值列,并用If块检查它。

我的代码如下:

  create proc billRet 
as 
BEGIN
DECLARE @amt float
set @amt=select amount from bill where Id='2425'
If (@amt>1100.50 )
Begin
select @amt
print 'Amount greater '+@amt;
END
Else
Begin
select @amt
print 'Amount Smaller'+@amt
END
END
Go

它在print语句和@amt变量声明中显示错误。

请告诉我我在哪里犯错。

请帮帮我。

2 个答案:

答案 0 :(得分:2)

该类型位于变量名称之后:

DECLARE @amt float;

您必须手动转换为字符串并连接以使打印工作:

print 'Amount greater ' + CONVERT(varchar(20),@amt);

(如果您不执行CONVERTCAST,则SQL Server将尝试将字符串转换为float并将两者一起添加)

也可能想要:

select @amt=amount from bill where Id='2425'

答案 1 :(得分:1)

试试这个,

SET @amt = (select amount from bill where Id='2425')

这个,

print 'Amount greater ' + CAST(@amt AS VARCHAR(50));
相关问题