Error in Synapse Stored Procedure

Jaykumar Patel 0 Reputation points
2024-03-19T14:49:04.5933333+00:00

Hi I am getting below

{ "errorCode": "2402",
 "message": "Execution fail against sql server. Please contact SQL Server team if you need further support.
 Sql error number: 156. 
Error Message: Incorrect syntax near the keyword 'AS'.",
 "failureType": "UserError",
 "target": "Stored procedure1",
 "details": [] }

USE gold_db
GO

CREATE OR ALTER PROC CreateSQLServerlessView_gold @ViewName nvarchar(100) 
AS 
BEGIN 
   
DECLARE @statement VARCHAR(MAX)
    SET
        @statement = N'CREATE OR ALTER VIEW '+@ViewName+' AS
            SELECT *
            FROM
                OPENROWSET(
                BULK ''https://jaykumardeproject.dfs.core.windows.net/gold_db/Level_2_transformed_data/' + @ViewName + '/'',
                FORMAT = ''DELTA''  
            ) as [result]
        ' 
EXEC (@statement)

END
GO
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,384 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. BhargavaGunnam-MSFT 26,226 Reputation points Microsoft Employee
    2024-03-19T18:11:52.65+00:00

    Hello Jaykumar Patel,

    Welcome to the Microsoft Q&A forum.

    The issue seems to be with the syntax. Synapse doesn't support 'Alter'

    Can you please remove 'OR ALTER' from your SP definition.

    Reference document: https://learn.microsoft.com/en-us/azure/synapse-analytics/sql/develop-stored-procedures

    User's image

    I hope this helps.