As above, I cannot type my queries on multiple lines in Jupyter, which is annoying because it is harder to write and read my own queries. Is there a way to toggle multiple and single line input? I have googled quite a few times but the documentation doesn't seem much help.
PS: found the silly solution of typing '%%sql' instead of '%sql'
This is pretty easy to do using standard python syntax. Use the triple quote operator.
query = """
select
foo
from
bar
"""
Building on above answer, use the pyodbc package, establish the connection, then query the database and bring data into Python memory.
import pyodbc
import pandas as pd
cnxn = pyodbc.connect('DSN=ODBC Connector Name', autocommit=True)
df = pd.read_sql_query("""
select
foo
from
bar
""",
cnxn
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With