Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

voting query not working anymore

Posted on 2007-03-23
4
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

604 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