I need to edit the data from MSSQL through Python. I have already catched the whole table from MSSQL Server but I just need to fetch a few data like due day and due day +2 from this table.
Here is my Python code:
from smtplib import SMTP
from sqlalchemy import create_engine
from datetime import datetime
from datetime import timedelta
import pymssql
import pandas as pd
db_eng=create_engine(‘mssql+pymssql://mtbtestee:Aa12366@@TAWSQLDBA01\TAMSSDBA01/MTB_TEST_EE’)
query_string='select* from [MTB_TEST_EE].[dbo].[PM_calendar_rawdata] ’
result=pd.read_sql(query_string,db_eng).drop_duplicates()
result
Here is my MSSQL code
SELECT *
FROM [MTB_TEST_EE].[dbo].[PM_calendar_rawdata] with (nolock)
where [Due_Date] >= convert (date,CURRENT_TIMESTAMP)
and [Due_Date] < convert (date,CURRENT_TIMESTAMP+3)
I want to ask how to edit the python code that I can just fetch due day and due day +2 from MSSQL Server in python
Thanks everyone for help!
(the following lines doesn’t seem to work , when I executed it, instead of extracting data within 2 days after due day, it fetched the whole table)
where [Due_Date] >= convert (date,CURRENT_TIMESTAMP)
and [Due_Date] < convert (date,CURRENT_TIMESTAMP+3)