I am trying to run a raw T-SQL query that writes tables in the database. I experimented with both SELECT INTO and CREATE AS but both failed. The query containing SELECT INTO executes without errors but doesn't do anything, whereas the query with CREATE TABLE AS returns a Incorrect Syntax error. Does anyone know if this operation is possible using sqlalchemy (pyodbc) or a workaround?
query = 'select top 10 * into dbo.test_table from dbo.main_table'
# or
query2 = 'create table dbo.test_table from (select top 10 * from dbo.main_table)'
engine = create_engine(....)
conn = engine.raw_connection()
cursor = conn.cursor()
result = cursor.execute(query)