Solved

voting query not working anymore

Posted on 2007-03-23
4
207 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now