Evaluate Ratio

  • Hi,

     

    I have a column which is stored in database as varchar.The vaue it contains is like '1/8'(ratio).

    I need to use this in calculations,I am not able to use cast or convert as it taking '/' and not evaluating the ratio.is there any way I can do this?

    Thanks,

    Ssm


    thanx...,

    SSM

  • Can you post more information >

    - Table definition

    - Sample data

    - Required results

  • The data type of column is varchar(512),

    Sample values are

    1/7

    1/8

    1/6

    1/9

    I need to divide by these ratios.

    Thanks,

    ssm

     


    thanx...,

    SSM

  • Declare @demo table (Ratio varchar(7) not null primary key clustered)

    Insert into @demo (Ratio) values ('4/7')

    Insert into @demo (Ratio) values ('1/6')

    Insert into @demo (Ratio) values ('1/7')

    Insert into @demo (Ratio) values ('1/8')

    Insert into @demo (Ratio) values ('1/9')

    Insert into @demo (Ratio) values ('11/92')

    Insert into @demo (Ratio) values ('/92')

    SELECT

    dtRatios.Ratio

    , dtRatios.Numerator

    , dtRatios.Denominateur

    , dtRatios.Numerator / dtRatios.Denominateur AS fFloat

    FROM

    (

    SELECT

    Ratio

    , CONVERT(INT, LEFT(Ratio, Charindex ('/', Ratio, 1) - 1)) AS Numerator

    , CONVERT(DECIMAL(18,1), RIGHT(Ratio, LEN(Ratio) - (Charindex ('/', Ratio, 1)))) as Denominateur

    FROM @demo

    WHERE Charindex ('/', Ratio, 1) > 1

    ) dtRatios

  • Thanks,

    ssm


    thanx...,

    SSM

  • HTH.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply