Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Not able to get total of a coloumn.

Author  Topic 

tusharkashyap
Starting Member

3 Posts

Posted - 2005-01-07 : 01:46:05
declare @totMTD as numeric
set @totMTD= (SELECT cast(count(c.termcode) as numeric) from fbdbsrv.BCBS.dbo.Calls c inner join fbdbsrv.BCBS.dbo.Termcodes tc on c.termcode=tc.termcode
where convert(varchar(30),c.calldate,101) between convert(varchar(30),@frdt,101) and convert(varchar(30),@tdt,101))

..... Above query will show the Total amount for @frdt, @tdt........


----------------------------------------------------------------

SELECT ' MTD %' as [Monthdates],Description,
case when isnull(count(c.termcode),0)<>0 then str(isnull(COUNT(c.Termcode),0)*100.0/(CASE WHEN @totMTD <>0 THEN @totMTD ELSE 1 END) ,5,2)+'%' else str(0.00,4,2)+'%' end AS 'mtdPer'
FROM rptBCBS AS P left outer JOIN fbdbsrv.BCBS.dbo.Calls AS C
ON p.Termcode =c.TermCode
--where convert(Varchar(30),c.calldate,101) between convert(varchar(30),@frdt,101) and convert(varchar(30),@tdt,101) --= CONVERT(varchar(30),C.Calldate,101)
where convert(datetime,calldate) between convert(datetime,@frdt) and convert(datetime,DateAdd(d, 1,@tdt ) )
GROUP BY p.[Description]
order by p.[Description]

---------Above second Query is to get the total of MTD coloumn -------- But its not showing the whole colums total , means its showing the last date's total... can anyone tell me how to get the total for the MTD coloumn.



Thanks for your time
   

- Advertisement -