Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

ORDER BY Không thực thi trong Function SQL MSSMS 18

16:52 08-07-2021 507 lượt xem 0 bình luận

CREATE FUNCTION LOEMPLOYEE(@STAFFID CHAR(10))
RETURNS TABLE
AS
RETURN
(
SELECT ST.STAFFID, ST.STAFFNAME, RE.RELATIVENAME, AG.DAYS, COUNT(PR.PRJID) AS 'Total PROJECT'  FROM dbo.PROJECT AS PR, dbo.ASSIGNMENT AS AG, dbo.STAFF AS ST,dbo.RELATIVES AS RE
WHERE PR.PRJID = AG.PRJID AND AG.STAFFID = ST.STAFFID AND ST.STAFFID = RE.STAFFID AND @STAFFID = ST.STAFFID
GROUP BY ST.STAFFID, ST.STAFFNAME, RE.RELATIVENAME, AG.DAYS
ORDER BY AG.DAYS DESC
)
GO

Vấn đề:

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
 

Ai chỉ mình cách khắc phục với ạ đề bài là: 

Write a function that returns a list of: Employee CODE, employee name, employee's relative name, total  number of projects participated, total time spent participating. The list decreases according to the total number of projects, if the total number of projects is equal, it will gradually increase with the total number of time participated

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập

Câu hỏi mới nhất