Solved

voting query not working anymore

Posted on 2007-03-23
4
205 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

744 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

16 Experts available now in Live!

Get 1:1 Help Now