Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. go
  2. drop function passedCheck
  3. go
  4. create function passedCheck (@studentno int)
  5. returns Char(15)
  6. as
  7. BEGIN
  8. declare @res char(15)
  9. -- her skal du indsætte din T-SQL kode
  10. declare @average decimal(10,2)
  11. declare @sum decimal(10,2)
  12. declare @avgThree decimal(10,2)
  13. declare @bottomtwo decimal(10,2)
  14. declare @strangeAvg decimal(10,2)
  15. SELECT @average = avg(grade * 1.0) from grades WHERE grades.studentno = @studentno
  16. SELECT @avgThree = avg(y.grade * 1.0) from (select TOP 3 grade from grades WHERE grades.studentno = @studentno ORDER BY grade desc) as y
  17. SELECT @bottomtwo = sum(x.grade * 1.0) from (select TOP 2 grade from grades WHERE grades.studentno = @studentno ORDER BY grade asc) as x
  18. SELECT @strangeAvg = @avgThree + @bottomtwo
  19.  
  20. IF @average > 5.5 AND @strangeAvg > 13
  21. select @res = 'PASSED'
  22. ELSE
  23. select @res = 'FAILED'
  24.  
  25. RETURN @res
  26. END
  27. go
  28. select name,dbo.passedCheck(studentno)
  29. from student
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement