# Thread: SQL Script for comman denominator

1. Registered User
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. Registered User
Join Date
May 2005
Location
South Africa
Posts
1,369
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. Registered User
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. Resident Curmudgeon
Join Date
Feb 2004
Location
In front of the computer
Posts
15,579
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

5. Registered User
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
•