Solved

voting query not working anymore

Posted on 2007-03-23
4
208 Views
Last Modified: 2010-03-19
this query is working perfectly in access.  i created the table same structure in sql server 2005 and it wont show the percentages.  it says 0 as results

SELECT TOP 6 Count(vote.voteid) AS ['Count Of Teams'], racerinfo.racername, (((Count(vote.voteid))/(select count(voteid) from vote))*100) AS TotalPercentage
FROM vote, racerinfo
WHERE (((vote.voteid)=[racerinfo].[ID]))
GROUP BY racerinfo.racername, vote.voteid
ORDER BY Count(vote.voteid) DESC
0
Comment
Question by:gianitoo
  • 2
4 Comments
 
LVL 16

Expert Comment

by:rboyd56
ID: 18783273
So the query returns no records?

If this is the case, have you verified that there are records in the vote table that have a corresponding record in the racerinfo table based on the voteod and ID columns.
0
 
LVL 1

Author Comment

by:gianitoo
ID: 18783339
no only for percentage column.   i know i have many votes

can u look to see if query looks ok
0
 
LVL 16

Expert Comment

by:rboyd56
ID: 18783399
TSQL is not my strongest point so I may not be the best to say, but it looks OK to me.
0
 
LVL 11

Accepted Solution

by:
dready earned 500 total points
ID: 18783789
I think that the problem is, that if you divide an integer by an integer in T-sql, the result is an integer that has any fractional part of the result truncated.
So you should cast Count(vote.voteid) to real. SOmething like this (parentheses might be in the wrong place, not sure). Another solution might be to use the round() function.



SELECT TOP 6 Count(vote.voteid) AS ['Count Of Teams'], racerinfo.racername, (((Cast(Count(vote.voteid) as real))/(select cast(count(voteid) as real) from vote))*100) AS TotalPercentage
FROM vote, racerinfo
WHERE (((vote.voteid)=[racerinfo].[ID]))
GROUP BY racerinfo.racername, vote.voteid
ORDER BY Count(vote.voteid) DESC

good luck,

dready
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question