0

I would like to create a SQL table from an existing table. I'm using the turbodbc module (which is very similar to 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'"))

However, I get the error message:

ODBC error
state: 42000
native error code: 156
message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'select'.
2
  • Try to put your select code in brackets () start before select and end after 'P' Commented Mar 4, 2020 at 7:18
  • @VBoka I get "Incorrect syntax near '('" , native error code 102 Commented Mar 4, 2020 at 7:21

1 Answer 1

2

Try to use this syntax:

select * into Test_Puts from  OptionValue where call_put = 'P'

So, instead of this:

" create table Test_Puts as"
" select * from OptionValue"
" where call_put = 'P'"

use this:

" select * into Test_Puts"
" from  OptionValue"
" where call_put = 'P'"
Sign up to request clarification or add additional context in comments.

4 Comments

Hi @thomas.mac , so, does this helps ? Thanks for the feedback.
thanks for the answer, the upside is it does not get an error, but the downside is it takes a very long time to run, so not sure what end result looks like. Is there more an efficient way to run the code?
Hi @thomas.mac what is the number of rows you are selecting ?
670 million rows !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.