SO Im having trouble trying to figure this out. I want the option to pass a variable into a function or not to pass a variable into the function. I have tried a few ways. This is my latest way but it still doesn't work.
I am basically either passing or not passing the variable 10538 into the function. I have an if else within the function that I want to work based on whether the variable is present or not i.e. has been passed or not. If it is passed it shold pull the data associated with the variable 10538 from the SQL database or if it not passed it will pull ALL the data from all the records in the SQL database.
Any ideas? Thanks
fundbhID = 10538
def AUMVaR(fundbhID):
if not fundbhID:
fundVaR = pd.read_sql_query("""
select *
from vwExposure_VaR""",conn)
fundVaR = pd.DataFrame(fundVaR)
else:
fundVaR = pd.read_sql_query("""
select *
from vwExposure_VaR
where BaseHoldingID=""" + str(fundbhID) + """ORDER by ReportingDate asc"""
,conn)
fundVaR = pd.DataFrame(fundVaR)
return fundVaR
fundVaR()
#or one could pass with the variable :
fundVar(10538)
Thanks for your help! Appreciated.