« Previous Next »

Answered Thread: How to divide a number in SQL

Last post 11-13-2009 6:31 AM by wallin. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 10-13-2009, 1:33 PM

    • massel
    • Not Ranked
    • Joined on 10-09-2008, 8:37 PM
    • Posts 7

    How to divide a number in SQL

    Hello, I have the following SQL query that works fine:

    SELECT cs-uri-stem, SUM(sc-bytes) as GB, count(*) AS hits INTO C:\test.csv FROM * GROUP BY cs-uri-stem" -i: w3c -o: csv

    What I want to do is divide the number I get in SUM(sc-bytes) as GB  by 1000000000.  I was able to use the DIV function, but it drops all the zeros after the decimal and I want to keep those.  I tried using a simple statement like SUM(sc-bytes) / 1000000000 as GB, but I get an error in LogParser.  Thanks for any help.

  • 10-21-2009, 1:35 PM In reply to

    • massel
    • Not Ranked
    • Joined on 10-09-2008, 8:37 PM
    • Posts 7

    Answered Re: How to divide a number in SQL

     I figured it out.  The problem was that I needed to convert the result of SUM(sc-bytes) to a REAL number using the TO_REAL function.  The final working query looks like this:

     SELECT cs-uri-stem, DIV(TO_REAL(SUM(sc-bytes)),1000000000) as GB, count(*) AS hits FROM * GROUP BY cs-uri-stem ORDER BY cs-uri-stem

     

  • 11-13-2009, 6:31 AM In reply to

    • wallin
    • Not Ranked
    • Joined on 11-13-2009, 6:09 AM
    • Posts 3

    Re: How to divide a number in SQL

    im not too familiar with sql but i would assume it has something to do with data types maybe? for example if it was integer it would only return a whole number such as 2 or 0 in your case, im not too sure about this in sql as i dont do it but generally that could be the problem
Page 1 of 1 (3 items)
Microsoft Communities