Reputation: 867
I have a stored procedure mentioned as below. I'm using SQL Server 2008 R2. When I run this stored procedure from SQLCMD it's working and the stored procedure is created, but when I execute the same from SSMS it's failing with the error below.
Msg 207, Level 16, State 1, Procedure TestProc, Line 5 Invalid column name 'col1.
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER OFF GO
CREATE PROC [dbo].[TestProc]
AS
BEGIN
SELECT t.col1 FROM table t /* But note that col1 is not in table t*/
END
RETURN
How can this problem be fixed?
Upvotes: 0
Views: 835
Reputation: 12051
Is it possible that when you tried to create the stored procedure in SQLCMD, that the table did not exist at the time? Due to the "deferred name resolution" feature of SQL Server, that would allow the stored procedure to be created.
If, at the time you tried to create the stored procedure, the table DID exist, but not the column, then you should be getting the error you are seeing regardless of whether you are using SQLCMD or SSMS.
Upvotes: 1