Sep-06-2019, 06:49 AM
How can pass the value captured in a variable using input() to a where clause in a select statement?
def ada(): import pyodbc import pandas as pd conn = pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};' 'Server=ABCD400;' 'Database=TestDb;' 'Trusted_Connection=yes;') SQL_Query = pd.read_sql_query('''select distinct DoctorName,Department from [TestDb].[dbo].[EveryDayAvailability] ''', conn) df = pd.DataFrame(SQL_Query, columns=['DoctorName','Department']) print (df) DName = input("Please provide the name of the Doctor you would like to visit ?") print("Printed below are the list of appointments for this doctor ") SQL_Query = pd.read_sql_query('''select DoctorName,0900 from [TestDb].[dbo].[EveryDayAvailability where DoctorName=DName] ''', conn) df = pd.DataFrame(SQL_Query, columns=['DoctorName','0900']) print (df)