I am trying to create a stored procedure using pass-through query in SQL Server 2012, using MS Access 2010.
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'SCHtest')
EXECUTE sp_executesql N'create schema SCHtest'
GO
CREATE PROCEDURE [SCHtest].[SQLLrtest_2]
AS
BEGIN
INSERT INTO [dbo].[UploadTest] (.....)
In Access I get this error:
Run time error '3146':
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax nera 'GO'. (#102)
[Microsoft][ODBC SQL Server Driver][SQL Server]'CREATE/ALTER PROCEDURE' must be
the first statement in a query batch. (#111)
And if I copy-paste code to SQL Server - everything works just fine!
As it is written in the error, if I delete IF statement and GO, works in both Access and SQL. How to make it work without deleting IF statement?
Any help is highly appreciated!
Edgaras
GOis for management studio only, its not a t-sql command (stackoverflow.com/questions/2668529/t-sql-go-statement) so remove it, then you will get another error when you try to create the sp, see here stackoverflow.com/questions/55506/…