0

我正在使用SQL Server 2008R2并且我有以下脚本。

select * from orderSummaryTotal(@orderid,@sessionid)

select
    count(*) as Quantity,
    IsNull(Sum(VatAmount),0) As VATAmount,
    IsNull(Sum(NetAmount),0) As NetAmount,
    IsNull(Sum(GrossAmount),0) as GrossAmount
from tbOrderProduct
where
     Orderid = @orderid
 and sessionid = @sessionid

当我运行第二个查询时,它会返回我的值。即数量 3

但是,当我运行第一个查询时,它返回的数量为 0。

第一个查询是表值函数这是代码。

ALTER FUNCTION [dbo].[OrderSummaryTotal](@orderid varchar, @sessionid uniqueidentifier)
RETURNS TABLE as
RETURN
  select
      count(*) as Quantity,
      IsNull(Sum(VatAmount),0) As VATAmount,
      IsNull(Sum(NetAmount),0) As NetAmount,
      IsNull(Sum(GrossAmount),0) as GrossAmount
  from tbOrderProduct
  where
       Orderid = @orderid
   and sessionid = @sessionid

两个查询是相同的,但是为什么一个返回计数 3 而另一个不返回呢?有任何想法吗?

4

1 回答 1

4

原因是varchar您的函数定义中没有长度。

尝试将其更改为类似varchar(8000)或足够大以满足您的需要的数字。

于 2012-12-13T15:25:58.237 回答