user300485 user300485 - 5 months ago 20
SQL Question

Divide two numbers in SQL server

Here is my full code:

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))


I am always getting the @Avg_transaction_Per_CSR is 0.

Ex: @@total_Transaction = 5
@Total_CSR = 26

Answer

I suspect the type of @opendays

Declare @opendays as decimal(18,8))