SQL Server:
ALTER PROCEDURE [dbo].[Test_Pagination_Proc]
@DBNAME nvarchar(200),
@STOREDPROC nvarchar(200),
@INDEX int,
@PageSize int
/*
DECLARE @DBNAME nvarchar(200) = 'C110_victoribasco18_gmail'
,@STOREDPROC nvarchar(200) = 'Friends_Pagination'
,@INDEX int = 1
,@PageSize int = 4
EXEC [dbo].[Test_Pagination_Proc]
@DBNAME,
@STOREDPROC,
@INDEX,
@PageSize
*/
AS
BEGIN
DECLARE @SQL_QUERY nvarchar(4000) = N'EXEC ' + QUOTENAME(@DBName) + N'.dbo.' + QUOTENAME(@STOREDPROC) + N'@INDEX, @PageSize ';
CREATE TABLE #T1
(
Id int,
Title nvarchar(120),
Bio nvarchar(700),
Summary nvarchar(255),
Headline nvarchar(80),
Slug nvarchar(100),
StatusId int,
PrimaryImage nvarchar (300)
)
INSERT INTO #T1
EXECUTE sp_executesql @SQL_QUERY, N'@INDEX int, @PageSize int', @INDEX, @PageSize
SELECT Id
FROM #T1
END
The issue is that I need this procedure to hit other tables besides the one it is hitting now (Friends
table). The obvious blocker is that in my logic I'm stopped by the hard-coded table since I'm shoving the result of the @SQL_QUERY
which WILL ALWAYS BE a selection of columns.
I only need to test for the Ids and I'm wondering if there's such a way to only get my Ids back with logic that is ignorant of the other columns.
The biggest thing is that I can't change the fact that I'm hitting another procedure that again, WILL ALWAYS return to me multiple columns because of the different tables it'll be hitting.
** More context I've a few hundred other Databases that I'll be hitting that need to include a proc named "Friends_Pagination" that returns a paginated list of friends. There are other tables such as Users or Skills or Images that I need to test for pagination. I only want to test for the returned Ids and nothing else. However, I must run their stored proc. Consequently, their stored proc returns more than just a list of Ids. I only need that list of Ids rather than accepting all of their data then filtering over the Id columns ... I'm wondering if I could just accept the Ids.