Hello,
I get the following error when I try to create this stored proc. I think it may have something to do with the two joins.
Msg 8156, Level 16, State 1, Procedure sp_wisetopic_landing_getPaged_FeaturedAlbums, Line 16
The column 'ArtistId' was specified multiple times for 'PagedData'.
Here is the QUERY:
create procedure sp_wisetopic_landing_getPaged_FeaturedAlbums
@pageSize int,
@pageNumber int
AS
DECLARE @FirstRow INT,
@LastRow INT
SELECT @FirstRow = ( @PageNumber - 1) * @PageSize + 1,
@LastRow = @PageSize + (@PageNumber - 1) * @PageSize;
WITH PagedData AS
(
SELECT A.*,
C.ArtistId,
ROW_NUMBER() OVER (ORDER BY sortOrder DESC) AS RowNumber
FROM
wisetopic_artist_album A
INNER JOIN
wisetopic_artist_featuredAlbums B
ON
A.albumId = B.albumId
INNER JOIN
wisetopic_artist c
ON
A.artistid = c.artistid
)
SELECT RowNumber, *
FROM PagedData
WHERE RowNumber between @FirstRow AND @LastRow
ORDER BY RowNumber ASC;