# Thread: how to calculate percentage

1. Registered User
Join Date
Jan 2004
Posts
51

## Unanswered: how to calculate percentage

b/w two colums?

i have two numberic columns
i want percentage of column2/column1
They are on separate table.. l am intended to creat view with my results.
thanks

2. Registered User
Join Date
Jan 2004
Posts
40
just do select table1.column1/table2.column2 from table1,table2

are the tables related in anyways? are they just numeric values that have nothing to do with each other? i need more information to help

3. Registered User
Join Date
Jan 2004
Posts
51
yes they are related and numberic
it gives me 0{zero] through in the results

i did table1.column1/table2.column2 as Percentage from table1,table2
do i have to create column? why outputing 0's only?

4. Registered User
Join Date
Jan 2003
Location
Massachusetts
Posts
5,863
Probably one or both columns are declared as integer. Try:

select convert(numeric(38, 19), table1.column1)/convert(numeric(38, 19), table2.column2) from table1,table2

5. Registered User
Join Date
Jan 2004
Posts
51
error
Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'dbo.table1' does not match with a table name or alias name used in the query.

this column name has space and im using it like

select convert(numeric(38, 19), table1.[column1 name])/convert(numeric(38, 19), table2.column2)

6. Registered User
Join Date
Jan 2004
Posts
40
i just ran it and it worked fine

select convert(numeric(38,19), table1.[a c])/convert(numeric(38,19), table2.[b d])
from table1, table2

i guess double check that you are using the right DB, and you've typed everything correctly. Otherwise can you post up your query for me to look at?

7. Registered User
Join Date
Jan 2004
Posts
51
thks
it's working

8. Registered User
Join Date
Jan 2004
Posts
51
do you know how to format this to 2 decimal places?

9. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595