tags:

views:

22

answers:

2

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.

+2  A: 

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.

Kirk Woll
+1  A: 

Why would you name the cte the same as the view name?

HLGEM