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.
| Author |
Topic |
|
Technical Edge
Starting Member
13 Posts |
Posted - 2001-05-10 : 23:33:12
|
| Here's what I got.DECLARE @Total NUMERIC(9)DECLARE @VotingYes NUMERIC(9)DECLARE @VotingNo NUMERIC(9)DECLARE @VotingDunno NUMERIC(9)DECLARE @AgreeCent NUMERIC(9)DECLARE @DisAgreeCent NUMERIC(9)DECLARE @DontKnowCent NUMERIC(9)SET @Total = (SELECT COUNT(PollNumber) FROM RandomPolls)SET @VotingYes = (SELECT COUNT(PollNumber) FROM RandomPolls WHERE PollNumber = 1)SET @VotingNo = (SELECT COUNT(PollNumber) FROM RandomPolls WHERE PollNumber = 2)SET @VotingDunno = (SELECT COUNT(PollNumber) FROM RandomPolls WHERE PollNumber = 3)SET @AgreeCent = (@VotingYes / @Total * 100)SET @DisAgreeCent = (@VotingNo / @Total * 100)SET @DontKnowCent = (@VotingDunno / @Total * 100)SELECT COUNT(PollNumber) AS 'Total', ImageLocation,(SELECT COUNT(PollNumber) From RandomPolls WHERE PollNumber = 1) AS VotingYes,(SELECT COUNT(PollNumber) From RandomPolls WHERE PollNumber = 2) AS VotingNo,(SELECT COUNT(PollNumber) From RandomPolls WHERE PollNumber = 3) AS VotingDunno,(@VotingYes / @Total * 100) AS 'AgreeCent',CAST(@AgreeCent AS NVARCHAR(2)) AS 'Real AgreeCent',(@VotingNo / @Total * 100) AS 'DisAgreeCent',CAST(@DisAgreeCent AS NVARCHAR(2)) AS 'Real DisAgreeCent',(@VotingDunno / @Total * 100) AS 'DontKnowCent',CAST(@DisAgreeCent AS NVARCHAR(2)) AS 'Real DontKnowCent'FROM RandomPollsGROUP BY ImageLocationNow when I run this, I get the same calculations for all the different records in the table. I would like to have each record to get its own calculation. Is this possible?Thanks In Advance!Regards,Technical Edge************************Technical_Edge@yahoo.com************************ |
|
|
|
|
|