Results 1 to 9 of 9
  1. #1
    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. #2
    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. #3
    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. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    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. #5
    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. #6
    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. #7
    Join Date
    Jan 2004
    Posts
    51
    thks
    it's working

  8. #8
    Join Date
    Jan 2004
    Posts
    51
    do you know how to format this to 2 decimal places?
    like 20 instead of 0.02

  9. #9
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Umm....I'll just take a guess here...multiply by 100?

    I assume you meant that 0.02 should display as 2, not 20...
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •