Row_Number () and T-SQL View

I am trying to implement swap for presentation in T-SQL:

with TH_VW_UserFollowing  as
(
Select  FollowerID, 
        FollowingID, 
        FollowingFullName, 
        FollowingImage, 
        FollowingUserName,
        dbo.GetUserFollowers(FollowingID) AS Followers,
        ROW_NUMBER() OVER (order by dbo.GetUserFollowers(FollowingID) DESC ) AS 'RowNumber'   
from dbo.TH_VW_UserFollowing 
where FollowerID = @UserID 
)
Select  FollowerID, 
        FollowingID, 
        FollowingFullName, 
        FollowingImage, 
        FollowingUserName, Followers
from dbo.TH_VW_UserFollowing
Where RowNumber BETWEEN @startIdx AND @endIdx

For some reason, I get the following errors:

Msg 207, Level 16, State 1, GetUserUsersFollowing Procedure, Line 36
Invalid column name "RowNumber". Msg 207, Level 16, State 1,
GetUserUsersFollowing Procedure , Line 36 Invalid column name "RowNumber". Msg
207, Level 16, State 1, GetUserUsersFollowing Procedure, Line 34
Invalid Followers column name.

I used the same code for the table, but I do not know what is going on here. something is missing ...

Thank.

+3
source share
2 answers

You choose from the table , CTE, . SELECT, "FROM TH_VW_UserFollowing". CTE .

+2

cte , ?

+1

Source: https://habr.com/ru/post/1763124/


All Articles