Click here to Skip to main content
15,914,403 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Here is my stored procedure which is working perfectly in local SQL server but not working in web

SQL
create PROCEDURE [dbo].[searchresult]
      @PageIndex INT
      ,@PageSize INT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [id] ASC
      )AS RowNumber
      ,[id]
      ,[title]
      ,[type]
      ,[cost]
      ,[date]
     INTO Results
      FROM [test]
      SELECT * FROM Results
      WHERE RowNumber BETWEEN @PageIndex and (@PageSize+@PageIndex)-1
      DROP TABLE Results
END


For the first time when this above procedure executes it is showing
Invalid object name 'Results'

and for the next time of execution it is displaying
There is already an object named 'Results' in the database.
Posted
Updated 18-Jul-12 19:09pm
v2
Comments
dimpledevani 19-Jul-12 0:57am    
what problem exactly are you facing??
sahabiswarup 19-Jul-12 1:06am    
This errors are showing:
Invalid object name 'Results'
There is already an object named 'Results' in the database

1 solution

Try storing your data in a temp table as shown below

SQL
create PROCEDURE [dbo].[searchresult]
      @PageIndex INT
      ,@PageSize INT
AS
BEGIN
      SET NOCOUNT ON;
      SELECT ROW_NUMBER() OVER
      (
            ORDER BY [id] ASC
      )AS RowNumber
      ,[id]
      ,[title]
      ,[type]
      ,[cost]
      ,[date]
     INTO #Results
      FROM [test]
      SELECT * FROM #Results
      WHERE RowNumber BETWEEN @PageIndex and (@PageSize+@PageIndex)-1
      DROP TABLE #Results
END
 
Share this answer
 
Comments
sahabiswarup 19-Jul-12 1:12am    
Thanks a lot.. Tejas
__TR__ 19-Jul-12 1:14am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900