Question
SQL: What's wrong with my Stored Procedure?
Can anyone see what's wrong with this? I've been staring at
it for an hour.
I keep getting an error of:
------------
Error in UpdateNewsPosting stored procedure.
Invalid object name '#PostingItems'.
Microsoft OLE DB Provider for SQL Server
-------------
Here's the stored procedure:
-------------
CREATE proc dbo.UpdateNewsPosting
@postingID int
as
/* Clean up */
If exists (select * from tempdb.dbo.sysobjects where substring(name,1,13) =
'#PostingItems')
Drop table #PostingItems
/* Vars for Procedure */
DECLARE
@SqlRun varchar(1000)
/* Update Posting Date Fields */
Select @SqlRun = 'UPDATE WePostingContent_NEW SET DbPostDt_prod = DbPostDt
WHERE (PostID = ' + str(@postingID) +')'
Execute (@SqlRun)
/* Grab staging server data */
Select @SqlRun = 'SELECT * INTO #PostingItems from WePostingContent_NEW
WHERE (PostID = ' + str(@postingID) +')'
Execute (@SqlRun)
/* Delete Production Data */
Select @SqlRun = 'DELETE FROM [pubDB].publicSite.WePostingContent_NEW WHERE
(PostID = ' + str(@postingID) +')'
Execute (@SqlRun)
/* Move staging data to production */
INSERT INTO [pubDB].publicSite.WePostingContent_NEW
SELECT *
FROM #PostingItems
GO
-------------
-Darrel
I keep getting an error of:
------------
Error in UpdateNewsPosting stored procedure.
Invalid object name '#PostingItems'.
Microsoft OLE DB Provider for SQL Server
-------------
Here's the stored procedure:
-------------
CREATE proc dbo.UpdateNewsPosting
@postingID int
as
/* Clean up */
If exists (select * from tempdb.dbo.sysobjects where substring(name,1,13) =
'#PostingItems')
Drop table #PostingItems
/* Vars for Procedure */
DECLARE
@SqlRun varchar(1000)
/* Update Posting Date Fields */
Select @SqlRun = 'UPDATE WePostingContent_NEW SET DbPostDt_prod = DbPostDt
WHERE (PostID = ' + str(@postingID) +')'
Execute (@SqlRun)
/* Grab staging server data */
Select @SqlRun = 'SELECT * INTO #PostingItems from WePostingContent_NEW
WHERE (PostID = ' + str(@postingID) +')'
Execute (@SqlRun)
/* Delete Production Data */
Select @SqlRun = 'DELETE FROM [pubDB].publicSite.WePostingContent_NEW WHERE
(PostID = ' + str(@postingID) +')'
Execute (@SqlRun)
/* Move staging data to production */
INSERT INTO [pubDB].publicSite.WePostingContent_NEW
SELECT *
FROM #PostingItems
GO
-------------
-Darrel
