I am trying to implement paging for a View 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 a reason I am getting these errors :
Msg 207, Level 16, State 1, Procedure GetUserUsersFollowing, Line 36
Invalid column name 'RowNumber'. Msg 207, Level 16, State 1, Procedure
GetUserUsersFollowing, Line 36 Invalid column name 'RowNumber'. Msg
207, Level 16, State 1, Procedure GetUserUsersFollowing, Line 34
Invalid column name 'Followers'.
I've used the same code for a table, but I don't know what is happening here. something is missing...
Thanks.
You're selecting from the table and not the CTE you defined above. You should be doing in your final SELECT, "FROM TH_VW_UserFollowing". I'd also suggest giving your CTE a different name from your table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With