Below is my sample databricks code where ACTUAL_TABLE and TEST_TABLE are SQL tables.
I am trying to insert into ACTUAL_TABLE from TEST_TABLE in databricks using pyodc connection.
mssql_db.sql
is my connection and the connection is working as expected. Code executes without any error but not inserting any data into the table. Looks like sp_executesql
not working from databricks.
V_SQL='INSERT INTO dbo.ACTUAL_TABLE(NAME,GENDER) SELECT ZNAME,GENDER from dbo.TEST_TABLE'
mssql_db.sql(f"""begin declare @V_SQL NVARCHAR(MAX);
begin
set @V_SQL=N'{V_SQL}'
EXECUTE sp_executesql @V_SQL;
end
end""")
Is there any other way to fulfil this requirement. I wanted to insert it from databricks only.
I also tried creating the proc in SQL and calling that proc from databricks even that didn't work.
1条答案
按热度按时间5ssjco0h1#
Follow the below approach, I reproduce the same thing in my environment as per your requirement.
This is my demo table
ACTUAL_TABLE1
.Now, you can check Azure Databricks connected to the SQL server
Code:
Successfully executed and inserted the data into ACTUAL_TABLE1 using above code:
Output: