我在SQL Server中有这个存储过程
create procedure [dbo].[netprice]
@ItemCode44 int,
@AgentID44 int
as
begin
declare @netprice float = (select isnull((select(select sum (Price * Quantity)) -
(select isnull(sum(amount), 0)
from Orders
where ProcessID = 10
and orders.ContractID in (select ContractID from ItemsMoves where InAgentID=@AgentID44 and
ItemCode=@ItemCode44) ))
/(select sum (Quantity) ),0) as netpric from ItemsMoves
where InAgentID =@AgentID44 and Delivered=0 and ItemCode=@ItemCode44)
return @netprice
end
我从另一个像这样的存储过程调用它
DECLARE @netprice float
EXEC @netprice = netprice2 @ItemCode, @SuppID
问题是当我保存@netprice
的值时,它被保存为整数,我需要它是浮点数
你误解了这里的 return 语句。这与面向对象的编程语言不同,在面向对象的编程语言中,return 允许您将值带回函数或方法之外。
返回与调用退出代码相同。它是 0 或另一个由 Microsoft 定义的非零整数。 return (Transact-SQL(
您要做的是向调用方返回一个输出值。
接受输入参数并以输出参数的形式将多个 br 值返回给 调用过程或批处理...
出 |输出 指示参数是输出参数。使用 OUTPUT 参数将值返回给过程的调用方。文本、ntext 和图像参数不能用作输出参数,除非该过程是 CLR 过程。输出参数可以是游标占位符,除非该过程是 CLR 过程。不能将表值数据类型指定为过程的 OUTPUT 参数。
创建过程
如果只有一列是整数(可能是数量( - 将其隐藏为浮点数:
sum(Price*cast(Quantity as float))
存储过程始终返回 int 返回 (事务处理 SQL( Microsoft
文档在计算中,变量值必须具有小数。您正在除以 2 个整数,但只有一个变量隐式转换为小数。这将导致没有小数的结果。
您需要(隐式转换(向两个变量添加一个十进制 ,0。
Int / int = int
Int / decimal = int
Decimal / decimal = decimal
在手机上接听