Execute stored procedure in Azure Data Platform - Post SQL Scripts

Viewed 81
1 Answers

I created a test to prove that the stored procedure can be called in the Post SQL scripts.

I created two tables:

CREATE TABLE [dbo].[emp](
    id int IDENTITY(1,1),
    [name] [nvarchar](max) NULL,
    [age] [nvarchar](max) NULL
) 


CREATE TABLE [dbo].[emp_stage](
    id int,
    [name] [nvarchar](max) NULL,
    [age] [nvarchar](max) NULL
) 

I created a sotred procedure.

create PROCEDURE [dbo].[spMergeEmpData]
AS
BEGIN
SET IDENTITY_INSERT dbo.emp ON
   MERGE [dbo].[emp] AS target
   USING [dbo].[emp_stage] AS source
   ON (target.[id] = source.[id])
   WHEN MATCHED THEN
      UPDATE SET name = source.name,
       age = source.age

    WHEN NOT matched THEN

       
       INSERT (id, name, age)
      VALUES (source.id, source.name, source.age);
    TRUNCATE TABLE [dbo].[emp_stage]
END

I will copy the csv file into my Azure SQL staging table [dbo].[emp_stage], then use stored porcedure [dbo].[spMergeEmpData] to transfer data from [dbo].[emp_stage] to [dbo].[emp].

enter image description here

Enter the stored procedure name exec [dbo].[spMergeEmpData] in the Post SQL scripts field. enter image description here

I successfully debugged. enter image description here

I can see the data are all in TABLE [dbo].[emp].
enter image description here

Related