October 28, 2010 at 9:58 am
I have tow tables thus:
TABLE_A
PCode MonthPop
5F5400000
5F7777777
5HG222224
5HP153086
-
TABLE_B
PCode MonthPop
5F5200000
5F7727737
5HG112334
5HP654332
How do i go about calculating a percentage difference between A and B on the MonthPop fields i.e. where 5F5 would be %50?
Thank you
October 28, 2010 at 10:36 am
DECLARE @TABLE_A TABLE (PCode char(3), MonthPop int)
INSERT INTO @Table_A
SELECT '5F5', 400000 UNION ALL
SELECT '5F7', 777777 UNION ALL
SELECT '5HG', 222224 UNION ALL
SELECT '5HP', 153086
DECLARE @TABLE_B TABLE (PCode char(3), MonthPop int)
INSERT INTO @TABLE_B
SELECT '5F5', 200000 UNION ALL
SELECT '5F7', 727737 UNION ALL
SELECT '5HG', 112334 UNION ALL
SELECT '5HP', 654332
SELECT a.PCode,
CAST(CAST(b.MonthPop / CAST(a.MonthPop as decimal(10,2)) * 100 as decimal(5,2)) as varchar) + '%'
FROM@Table_A a
INNER JOIN @Table_B b ON a.PCode = b.PCode
October 29, 2010 at 4:35 am
Thank you very very much John.
Andy
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply