有谁能告诉我这个脚本有什么问题:
IF @MODE = 'FRIEND-LIST-MANAGE'
DECLARE @TotalPages INT
BEGIN
SELECT @TotalPages = COUNT(*)/@PageSize
FROM Member a
INNER JOIN MemberConnection d ON d.ConnMemberID = a.MemberID
WHERE d.MemberID = @MemberID;
WITH FindMyFriends AS
(
SELECT ROW_NUMBER() OVER(sbuser.sf_DisplayName(a.MemberID) ASC) AS RowNum,
a.MemberID, -- 1
a.UserName, -- 2
a.City, -- 3
b.Abbr, -- 4
b.State, -- 5
c.Country, -- 6
a.AvatarSm, -- 7
a.AvatarMed, -- 8
a.AvatarLg, -- 9
sbuser.sf_MemberHasAudio(a.MemberID) AS HasAudio, -- 10
sbuser.sf_MemberHasVideo(a.MemberID) AS HasVideo, -- 11
sbuser.sf_MemberHasImages(a.MemberID) AS HasImages, -- 12
sbuser.sf_DisplayName(a.MemberID) AS DisplayName, -- 13
a.ProfileTypeID, -- 14
a.LastLogin, -- 15
a.CreateDate -- 16
FROM Member a
LEFT JOIN State b ON b.StateID = a.StateID
INNER JOIN Country c ON c.CountryID = a.CountryID
INNER JOIN MemberConnection d ON d.ConnMemberID = a.MemberID
WHERE d.MemberID = @MemberID
)
SELECT *
FROM FindMyFriends
WHERE RowNum BETWEEN (@PG - 1) * @PageSize AND @PG * @PageSize
ORDER BY sbuser.sf_DisplayName(a.MemberID) ASC
END
SQL服务器报告: 消息102,级别15,状态1,过程sp_memberConnection,第117行 '。'。
附近的语法不正确非常感谢任何帮助......
答案 0 :(得分:1)
ROW_NUMBER
需要ORDER BY
。
假设sbuser.sf_DisplayName
是一个我认为你需要的UDF。
ROW_NUMBER() OVER(ORDER BY sbuser.sf_DisplayName(a.MemberID) ASC)
这似乎是对UDF的潜在不良使用,因为它需要为源数据中的每一行评估UDF。可以用简单的JOIN
替换UDF吗?