0

I'm trying to rename a table using sp_rename but I am getting the following error when executing the query:

DECLARE @DateValue INT
SET     @DateValue = CONVERT(VARCHAR(8), GETDATE()-1, 112) 

DECLARE @ArchiveTableName VARCHAR(255) 
SET     @ArchiveTableName = 'dbo.tblProductPipeline_'+ CAST(@DateValue AS VARCHAR)


EXEC SP_RENAME 'dbo.tblProductPipeline_Daily', @ArchiveTableName

Error Message

Msg 15225, Level 11, State 1, Procedure sp_rename, Line 338
No item by the name of 'dbo.tblProductPipeline_Daily' could be found in the current database 'Nexus', given that @itemtype was input as '(null)'.

Can anyone please help me with my understanding of what's going wrong?

Thank you!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SQLseed
  • 13
  • 5
  • 1
    [Pinal Dave has a good blog on this](https://blog.sqlauthority.com/2016/01/05/sql-server-fix-sp_rename-error-msg-15225-no-item-by-the-name-of-s-could-be-found-in-the-current-database/) – S3S Apr 06 '18 at 15:57
  • Don't specify the schema name for @ArchiveTableName. Otherwise, the 'dbo.' will become the part of the table name (i.e. `[dbo].[dbo.tblProductPipeline_20180406]`. – Dan Guzman Apr 06 '18 at 16:23

1 Answers1

0

Fixed now - for some reason the table referenced was dropped...

SQLseed
  • 13
  • 5