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 |
|
Fatalsniper
Starting Member
45 Posts |
Posted - 2005-12-06 : 15:04:36
|
| Hey guys,I'm getting this resulton a query field calculated like this;SELECT ,field,bla,count(ID) * 100 / (SELECT * FROM Clients) FROM ...I get the expected results, but truncated to integers when the result is a real number...What's this all about???Thanks in advance... |
|
|
druer
Constraint Violating Yak Guru
314 Posts |
Posted - 2005-12-06 : 15:15:15
|
| Count returns an integer, and is multiplied by 100 which is an integer in the form you have it so your result will be an integer. If you want a real then you can CAST or CONVERT the value to a real. Or try changing 100 to 100.00 or 100 followed by however many 0's you want in your result. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2005-12-06 : 15:18:27
|
I'm guessing, but an integer [count(ID) * 100] divided by another integer [SELECT * FROM Clients] results in an integer. And I'm wondering how you divide by SELECT *, which gives a recordset???This might fix itSELECT CAST(COUNT(ID) as DECIMAL(5.2)) * 100.0 / (Whatever here)Give it a try and lettuce no what happens. |
 |
|
|
Fatalsniper
Starting Member
45 Posts |
Posted - 2005-12-06 : 16:32:39
|
| Guys Thanks a lot!!I solved it this way...STR(Count(*) * 100.00 / (SELECT Count(*) FROM Clients),5,2) as 'Percent' |
 |
|
|
|
|
|