Kyra
Kyra

Reputation: 5407

The T-SQL error "invalid column name" cites my procedure name when running it

I am copying a stored procedure from one database to another. I am currently fetching the stored procedure with:

select OBJECT_DEFINITION(OBJECT_ID(N'dbo.' + @stored_procedure_name, 'P'))

and store the returned string in the variable @stored_procedure_defn.

I then run the procedure with:

exec(@stored_procedure_defn)

However I am currently getting the error

Invalid column name 'stored_procedure_name'

What could be causing this? I have tried it with a couple different procedures and the only time they mention their name is in the create procedure [dbo].['stored_procedure_name'].

EDIT Sorry my error is elsewhere. Thanks for the help.

Upvotes: 0

Views: 492

Answers (1)

Philip Kelley
Philip Kelley

Reputation: 40319

Sounds like the stored procedure references a column that is not present in the "new" database. Note that the table is present, but the column (stored_proceudre_name) is not.

Based on what you've posted, the similarity of the invalid column name and your memvar name appears to be just a coincidence.

Upvotes: 1

Related Questions