[英]Python SQL Server - Create Table from Values from an existing Table
[英]create SQL table from existing table using pyodbc/turbodc in python
我想從現有表創建一個 SQL 表。 我正在使用 turbodbc 模塊(與 pyodbc 非常相似)。
# connect to database
conn = turbodbc.connect(connection_string="my_connection_string")
cursor = conn.cursor()
# execute SQL code
cursor.execute((" create table Test_Puts as"
" select * from OptionValue"
" where call_put = 'P'"))
但是,我收到錯誤消息:
ODBC error
state: 42000
native error code: 156
message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'select'.
嘗試使用以下語法:
select * into Test_Puts from OptionValue where call_put = 'P'
所以,而不是這個:
" create table Test_Puts as"
" select * from OptionValue"
" where call_put = 'P'"
用這個:
" select * into Test_Puts"
" from OptionValue"
" where call_put = 'P'"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.