[英]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.