我有一個存儲過程按分數來獲得一個療程的GPA乘以信貸的結果:調用存儲在另一個存儲過程的過程
ALTER PROCEDURE dbo.GpaCreditFromScore
(
@score INT,
@credits INT,
@gpaCredit INT OUTPUT
)
AS
IF (@score < 60)
BEGIN
SET @gpaCredit = 0.0
END
ELSE IF (@score < 62)
BEGIN
SET @gpaCredit = 1.0 * @credits
END
ELSE IF (@score < 65)
BEGIN
SET @gpaCredit = 1.7 * @credits
END
ELSE IF (@score < 67)
BEGIN
SET @gpaCredit = 2.0 * @credits
END
ELSE IF (@score < 70)
BEGIN
SET @gpaCredit = 2.3 * @credits
END
ELSE IF (@score < 75)
BEGIN
SET @gpaCredit = 2.7 * @credits
END
ELSE IF (@score < 80)
BEGIN
SET @gpaCredit = 3.0 * @credits
END
ELSE IF (@score < 85)
BEGIN
SET @gpaCredit = 3.3 * @credits
END
ELSE IF (@score < 90)
BEGIN
SET @gpaCredit = 3.7 * @credits
END
ELSE IF (@score < 95)
BEGIN
SET @gpaCredit = 4.0 * @credits
END
ELSE IF (@score <= 100)
BEGIN
SET @gpaCredit = 4.3 * @credits
END
而另一個存儲過程來計算所有學生的GPA乘信用:
ALTER PROCEDURE dbo.ComputeGpa
AS
;WITH x AS
(
SELECT StudentID, Score, rn = ROW_NUMBER() OVER
(PARTITION BY StudentID, CourseID
ORDER BY Semester DESC)
FROM dbo.UndergraduateScoreSet
)
SELECT StudentID, Gpa /* call dbo.GpaCreditFromScore here to get @gpaCredit */
FROM x
WHERE rn = 1
GROUP BY StudentID;
由於邏輯非常複雜,我不知道如何實現這一點。請大家幫忙〜
如果你有一個表列'LowerScoreBound','UpperScoreBound '和'乘數',你可以很容易地獲得乘數作爲一個基於集的操作。然後,你可以大大簡化你的存儲過程(這應該是一個UDF)或完全消除它。 – 2012-08-10 06:19:44
與其編輯您的問題以包含答案,您應該將答案發布爲...答案(然後請回滾您的編輯)。 – 2012-08-10 07:24:18