在SQL Server中划分两个数字

时间:2016-06-07 16:43:17

标签: sql sql-server sql-server-2008

这是我的完整代码:

declare @total_csr as int
declare @total_Transaction as int
declare @Avg_days_Open as decimal(18,8)
Declare @Avg_transaction_Per_CSR as int

SELECT @total_csr = COUNT(*)  FROM [APMRS_RG2].[dbo].pdmmast  p where Plan_Num in ('510' ) and 
MONTH(p.Statdate) = @month and YEAR(p.statdate) = @Year

---- Total Transactions  --------
SELECT @total_Transaction = SUM(cast(transaction_count as int)) FROM [APMRS_RG2].[dbo].pdmmast  p where Plan_Num in ('510' ) and 
MONTH(p.Statdate) = @month and YEAR(p.statdate) = @Year

---- AVG Transaction Per CSR
select @Avg_transaction_Per_CSR = CAST(@total_Transaction as decimal(18,8)) / CAST(@total_csr as decimal(18,8))

我总是得到@Avg_transaction_Per_CSR为0。

Ex:@@ total_Transaction = 5     @Total_CSR = 26

2 个答案:

答案 0 :(得分:2)

我怀疑@opendays的类型

Declare @opendays as decimal(18,8))

答案 1 :(得分:0)

您应将所有变量声明为decimal(10,22)

declare @total_csr as decimal(10,2)
declare @total_Transaction as decimal(10,2)
declare @Avg_days_Open as decimal decimal(10,2)
declare @Avg_transaction_Per_CSR as decimal(10,2)