Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Error while creating stored procedure from SQLCMD - Must declare the scalar variable Expand / Collapse
Author
Message
Posted Saturday, February 02, 2013 10:16 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:43 PM
Points: 33, Visits: 164
Hello,

I'm Getting the following error when I run the below SQLCMD command and not sure how to resolve this issue:
C:\Test>sqlcmd -S localhost\TESTINSTANCE -i test.sql -v filepath=".\"

Changed database context to 'TEST_DB'.
Msg 137, Level 15, State 2, Server TOM\TESTINSTANCE, Line 18
Must declare the scalar variable "@indate".



Table EMP:
CREATE TABLE EMP (EMPID INT, EMPNAME VARCHAR(50), EMP_JOIN_DATE DATETIME);




Test.sql:

USE TEST_DB
GO
:r $(filePath)Upgrade_Script.sql
:r $(filePath)Create_StoredProcedures.sql
GO



Upgrade_Script.sql:
USE master
--GO

--50001
IF EXISTS(SELECT * FROM sys.messages WHERE message_id = 50001)
BEGIN
exec sp_dropmessage 50001
END
--go

PRINT '------------------------------------------------------------------------------------------------------------------------------------------------------------------'
print ' End of Upgrade_Script '
PRINT '------------------------------------------------------------------------------------------------------------------------------------------------------------------'
PRINT ' '
--GO



Create_StoredProcedures.sql:
CREATE PROCEDURE [TEST_DB].[dbo].[GetSP] @indate DateTime AS
BEGIN
SET NOCOUNT ON
SELECT * FROM EMP WHERE EMP_JOIN_DATE > @indate;
END
--GO


Thanks!
Post #1414980
Posted Monday, February 04, 2013 4:36 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 1,259, Visits: 4,260
I'm pretty sure you can't specify the entire three-part database name in a CREATE PROCEDURE call like that--if you change that to USE Test_DB and only specify the procedure name in the CREATE call, does it work?
Post #1415226
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse