Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 A simple query question that i need an answer...

Author  Topic 

jonasdavedomingo
Starting Member

33 Posts

Posted - 2004-09-11 : 03:03:45
Ok, Ive two tables named TBL_REPORTS that has 3 columns which are rep_RefNo, rep_PointID, and rep_Counter, and TBL_POINTS that has 2 columns which are pt_ID and pt_Points.

Let's say TBL_REPORTS has 2 rows:
rep_RefNo_______rep_PointID_______rep_Counter
__0001_____________2_______________7
__0002_____________1_______________11

and TBL_POINTS has 2 rows:
pt_ID_______pt_Points
__1___________20
__2___________50

query = "SELECT * FROM TBL_REPORTS ORDER BY POINTS";


I want to get all the rows in TBL_REPORTS where i will add the points and counter of each row. For row one, the total points must be 50 + 7 = 57 while row 2 has 20 + 11 = 31. and I want to sort the 2 rows in ascending order based on the total points. so in this case, row 2 must be displayed first because the total points is 31 while row 1's total points is 57.

I wana know what is the query for that. thanks!

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2004-09-11 : 05:19:24
SELECT
r.rep_RefNo,
r.rep_Counter + p.pt_Points AS Points
FROM
dbo.TBL_REPORTS AS r
JOIN dbo.TBL_POINTS AS p
ON r.rep_PointID = p.pt_ID
ORDER BY
r.rep_Counter + p.pt_Points

Mark
Go to Top of Page

jonasdavedomingo
Starting Member

33 Posts

Posted - 2004-09-11 : 07:05:53
ok thanks. i got it!
Go to Top of Page
   

- Advertisement -