divide INT get decimal output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Josh Phillips

    divide INT get decimal output

    I have written the following query and even though I used CAST if the
    number is less then 1 it show up as 0. Here is the query:

    select cast(count(Safe tyTrainingYN) AS FLOAT)
    from ICPCDATA
    where SafetyTrainingY N = 1 /
    (select count(SafetyTra iningYN)
    from ICPCDATA)

    Any help would be much appreciated.

    Thanks,

    jp


    remove _nospam_ for my email

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Rich Dillon

    #2
    Re: divide INT get decimal output

    Josh, is this what you're after?

    SELECT
    (SELECT CAST(COUNT(*) AS FLOAT)
    FROM ICPCDATA
    WHERE SafetyTrainingY N=1) /
    (SELECT COUNT(SafetyTra iningYN)
    FROM ICPCDATA)
    AS PercentYes

    In your query, you're looking for the count of rows where SafetyTrainingY N
    is equal to the fraction 1/count(...) (zero when the table has more than 1
    row due to integer division).

    Hope that helps,
    Rich


    "Josh Phillips" <phillips3_nosp am_@hotmail.com > wrote in message
    news:40914d9e$0 $203$75868355@n ews.frii.net...[color=blue]
    > I have written the following query and even though I used CAST if the
    > number is less then 1 it show up as 0. Here is the query:
    >
    > select cast(count(Safe tyTrainingYN) AS FLOAT)
    > from ICPCDATA
    > where SafetyTrainingY N = 1 /
    > (select count(SafetyTra iningYN)
    > from ICPCDATA)
    >
    > Any help would be much appreciated.
    >
    > Thanks,
    >
    > jp
    >
    >
    > remove _nospam_ for my email
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]


    Comment

    Working...