简体   繁体   中英

Sql statement to SQLAlchemy

How can I convert this SQL statement into SQLAlchemy python. Couldnt find any solution yet

Thanks in advance

select date_add(est_date, interval -WEEKDAY(est_date) day) FirstDayOfWeek

Tried this below query but didn't work func.dateadd(est_date, func.dayofweek(est_date), Interval()))

How about:

engine = sqlalchemy.create_engine(
    "mssql+pyodbc://"+user+":"+pwd+"@"+HOST+"/" + db + "?driver=SQL+Server+Native+Client+11.0?trusted_connection=yes",
    echo=False, fast_executemany=True)
query_read = "select date_add(est_date, interval  -WEEKDAY(est_date) day) FirstDayOfWeek"
with engine.begin() as conn:
    dfData_old = pd.read_sql(query_read, conn)

Replace PWD, DB, and HOST with your values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM