Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Location
    India,Mumbai
    Posts
    34

    Unanswered: SQL Script for comman denominator

    Hi Experts,
    Can you please help me to write script to calculate values for New numerator and new denominator

    Table Name : tbl_calc

    Numerator Denominator New Numerator New denominator
    1 2 2 4
    1 4 1 4
    1 4 1 4

    Something like below
    + + = 2/4 +1/4 +1/4 = 1

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Not entirely sure what you want, maybe this?
    Code:
    SELECT 
      old=sum(Numerator*1./Denominator),
      new=sum(NewNumerator*1./NewDenominator)
    FROM (SELECT --TestData
     1, 2, 2, 4 UNION ALL SELECT 
     1, 4, 1, 4 UNION ALL SELECT 
     1, 4, 1, 4 )TestData
    (Numerator, Denominator, NewNumerator, NewDenominator)

  3. #3
    Join Date
    Feb 2012
    Location
    India,Mumbai
    Posts
    34
    Nope nothing like this ..
    we need to calculate the values for column New numerator and new denominator
    based on numerator and denominator of the table - tbl_calc

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    If you only need to be able to work the calculation and don't need LCD, then you could use:
    Code:
    CREATE TABLE #frac (
       numerator    INT         NOT NULL
    ,  denominator  INT         NOT NULL
    )
    
    INSERT INTO #frac (numerator, denominator)
       SELECT 1, 2 UNION ALL
       SELECT 1, 4 UNION ALL
       SELECT 1, 4
    
    SELECT numerator, denominator
    ,  numerator * new_denominator / denominator AS new_numerator
    ,  new_denominator
       FROM #frac AS a
       CROSS JOIN (SELECT Round(Exp(Sum(Log(denominator))), 0) AS new_denominator
          FROM #frac) AS b
    
    DROP TABLE #frac
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  5. #5
    Join Date
    Feb 2012
    Location
    India,Mumbai
    Posts
    34
    ohh that's great..
    Thanks...

Posting Permissions

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