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 2005 Forums
 Transact-SQL (2005)
 divide colum1 by column2

Author  Topic 

nhess80
Yak Posting Veteran

83 Posts

Posted - 2009-08-21 : 16:45:42
I know this should be easy but when I run this the results don't come out right. Also I am dividing the columns and they have been calculated separately.

COUNT(*) AS AttemptCalls,
COUNT(CASE WHEN Duration > '0' THEN '1' END) AS CompleteCalls,
SUM(CONVERT(numeric(18), Duration) / 60) AS Duration,
COUNT(CASE WHEN Duration > '0' THEN '1' END) / COUNT(*) AS ASR

Ok so I would like the output to be for example

AttemptCalls = 10
CompleteCalls = 7
Duration = 60
ASR = 0.7

The problem is when I run this the ASR column is only returning either a 1 or a 0 and I’m not sure why if the AttemptCalls = CompleteCalls a 1 is returned anything else it returns a 0

Thanks for your help

Nick

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-21 : 16:57:24
COUNT(CASE WHEN Duration > '0' THEN '1' END) / convert(decimal(12,2),COUNT(*)) AS ASR



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nhess80
Yak Posting Veteran

83 Posts

Posted - 2009-08-21 : 17:01:53
Thank you very much

quote:
Originally posted by webfred

COUNT(CASE WHEN Duration > '0' THEN '1' END) / convert(decimal(12,2),COUNT(*)) AS ASR



No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-21 : 17:02:58
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -