473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Return percentages in the query.

Hello,

I'm trying to something that just works in Oracle, but does not in Sql
Server.

How can I get the percentage of two counts to be returned on each row
of the query?

select count(sid), /* all not the not null */
count(*),
(count(sid) / count(*) ) as percent_not_null,
4 as four,
(3/4) as three_over_four
from dbo.sysusers
70 82 0 4 0
Incredibly, it changes even 3/4 into a zero!

For efficiency, I want the percentage returned in the query.
And to not use variables and coding. Efficiency,
both of the server, and of my time.
Note: I am using dbo.sysusers as an EXAMPLE only. My real
query will be on user defined application tables.
What is the solution please?

Oct 13 '06 #1
4 1824
Integer math

here are 3 ways pick your poison

select 3/4,
(3*1.0)/4,
3.0/4,
convert(decimal(12,3),3)/4

Denis the SQL Menace
http://sqlservercode.blogspot.com/
sqlservernew...@yahoo.com wrote:
Hello,

I'm trying to something that just works in Oracle, but does not in Sql
Server.

How can I get the percentage of two counts to be returned on each row
of the query?

select count(sid), /* all not the not null */
count(*),
(count(sid) / count(*) ) as percent_not_null,
4 as four,
(3/4) as three_over_four
from dbo.sysusers
70 82 0 4 0
Incredibly, it changes even 3/4 into a zero!

For efficiency, I want the percentage returned in the query.
And to not use variables and coding. Efficiency,
both of the server, and of my time.
Note: I am using dbo.sysusers as an EXAMPLE only. My real
query will be on user defined application tables.
What is the solution please?
Oct 13 '06 #2
Incredibly, it changes even 3/4 into a zero!

This is called integer math.
http://classicasp.aspfaq.com/general...oes-4/5-0.html
Oct 13 '06 #3
>I'm trying to something that just works in Oracle, but does not in SQL Server. <<

Oracle is the one that does not work and SQL Server is the one that
follows Standards. Wait until you find out how Oracle also screws up
NULLs. If you want decimal placs, then you can CAST() the values to
your needed precision. If you use a number with a decimal point in
it, SQL Server will pick a default precision.

Oct 13 '06 #4

Try

select count(sid), /* all not the not null */
count(*),
(count(sid)*1.0 / count(*) ) as percent_not_null,
4 as four,
(3/4) as three_over_four
from dbo.sysusers
Madhivanan
sq*************@yahoo.com wrote:
Hello,

I'm trying to something that just works in Oracle, but does not in Sql
Server.

How can I get the percentage of two counts to be returned on each row
of the query?

select count(sid), /* all not the not null */
count(*),
(count(sid) / count(*) ) as percent_not_null,
4 as four,
(3/4) as three_over_four
from dbo.sysusers
70 82 0 4 0
Incredibly, it changes even 3/4 into a zero!

For efficiency, I want the percentage returned in the query.
And to not use variables and coding. Efficiency,
both of the server, and of my time.
Note: I am using dbo.sysusers as an EXAMPLE only. My real
query will be on user defined application tables.
What is the solution please?
Oct 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Avinash Dhoot | last post by:
Hi, I have a 5 row table with the following values. key value 1 5 2 10 3 15 4 15 5 5
0
by: michael | last post by:
I've got a 3-column layout using percentages to define width of each div-column. #left-col { width: 20%; background-color: green; float:left; } #center-col { width: 60%; background-color: blue;...
1
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals....
26
by: Mike Barnard | last post by:
Hi all. I am playing with html and css. I don't (yet) have a working site, I'm just trying to build a working, basic template I can use for a couple of ideas I have. I recall reading a...
5
by: Chris H | last post by:
I am wanting to write a function for a poker league manager that will detrmine players finishing points in a tournament depending on the amount of players that played... In other words when the...
1
by: Bob Alston | last post by:
I need to produce a report like this Color: # % ------ --- --- White 10 20 Black 25 50 other 15 30 ---- ---- Total 50 100
5
by: eliana82 | last post by:
I have problems calculating score percentages within groups. I have created a boat program in access where the information provided is name, team, boat and score. The first query I've done is...
3
by: martin DH | last post by:
Access 2003 I have a table (TASKS) filled with data from an external source. The table lists several tasks for employees to complete and has a text field (STATUS) that identifies where in the...
7
by: buddyr | last post by:
Hello, can I write a query that will give percentages of records in one field? table example: table1 IdNumber model condition 01 045 good 01 045 ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.