How to fix error code 202 when using stored procedure in Azure Synaspe

Velben27 20 Reputation points
2023-08-22T08:20:05.8766667+00:00

Hello all,

I need some assistance here.

I created a pipeline to run a stored produce inside a for each activity. I am getting the errors shown in the first code box below. I have checked the stored procedure code and it works when ran by itself. Each time I run this pipeline the syntax error moves to another table name.

The goal is to use the For Each activity with the store procedure to create a view for each table in the data lake.

Operation on target For each table name failed: Activity failed because an inner activity failed; Inner activity name: Stored procedure1, Error: Execution fail against sql server. Please contact SQL Server team if you need further support. Sql error number: 102. Error Message: Incorrect syntax near 'VIEWSalesOrderDetail'.

stored procedure code:

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://ebgenlake2.dfs.core.windows.net/gold/SalesLT/' + @ViewName + '/'',
                FORMAT = ''DELTA''
        ) AS [result]
    '
EXEC (@statement)

END
GO
Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,553 questions
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.
5,306 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 31,391 Reputation points
    2023-08-22T11:26:03.48+00:00

    I think the error you're encountering is related to a syntax error in the SQL statement that is dynamically constructed within the stored procedure.

    There is a space issue between the CREATE OR ALTER VIEW and the @ViewName.

    Try to update your query like below :

    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://ebgenlake2.dfs.core.windows.net/gold/SalesLT/' + @ViewName + '/'',
                    FORMAT = ''DELTA''
            ) AS [result]
        '
    EXEC (@statement)
    END
    GO
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.