Hi there. I found a couple really good articles and Stored Procedures for data paging on SQLTeam.com. My question has to do with whether or not it's OK to pass these SP's in a query string instead of creating an actual SP.The reason I want to do this is because I need to dynamically create the tables, columns, etc...and I don't know how to do this in a SP. Each bit of code calling this "function" will require different tables, columns, etc.I've included the code (and article links) below, is either of them better than the other? I'm new to SP's, so please go easy on me! <grin>Thanks for any help!]Al..VERSION 1http://www.aspfaqs.com/webtech/062899-1.shtmlCREATE PROCEDURE sp_PagedItems ( @Page int, @RecsPerPage int )AS-- We don't want to return the # of rows inserted-- into our temporary table, so turn NOCOUNT ONSET NOCOUNT ON--Create a temporary tableCREATE TABLE #TempItems( ID int IDENTITY, Name varchar(50), Price currency)-- Insert the rows from tblItems into the temp. tableINSERT INTO #TempItems (Name, Price)SELECT Name,Price FROM tblItem ORDER BY Price-- Find out the first and last record we wantDECLARE @FirstRec int, @LastRec intSELECT @FirstRec = (@Page - 1) * @RecsPerPageSELECT @LastRec = (@Page * @RecsPerPage + 1)-- Now, return the set of paged records, plus, an indiciation of we-- have more records or not!SELECT *, MoreRecords = ( SELECT COUNT(*) FROM #TempItems TI WHERE TI.ID >= @LastRec ) FROM #TempItemsWHERE ID > @FirstRec AND ID < @LastRec-- Turn NOCOUNT back OFFSET NOCOUNT OFF
...VERSION 2http://www.15seconds.com/Issue/010308.htmCREATE PROCEDURE "sprocInformationTechnologyProjects"@Page int,@Size intASDECLARE @Start int, @End intBEGIN TRANSACTION GetDataSetSET @Start = (((@Page - 1) * @Size) + 1)IF @@ERROR <> 0 GOTO ErrorHandlerSET @End = (@Start + @Size - 1)IF @@ERROR <> 0 GOTO ErrorHandlerCREATE TABLE #TemporaryTable( Row int IDENTITY(1,1) PRIMARY KEY, Project varchar(100), Buyer int, Bidder int, AverageBid money)IF @@ERROR <> 0 GOTO ErrorHandlerINSERT INTO #TemporaryTableSELECT ...// Any kind of select statement is possible with however many joins// as long as the data selected can fit into the temporary table.IF @@ERROR <> 0 GOTO ErrorHandlerSELECT Project, Buyer, Bidder, AverageBidFROM #TemporaryTableWHERE (Row >= @Start) AND (Row <= @End)IF @@ERROR <> 0 GOTO ErrorHandlerDROP TABLE #TemporaryTableCOMMIT TRANSACTION GetDataSetRETURN 0ErrorHandler:ROLLBACK TRANSACTION GetDataSetRETURN @@ERROR