Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Model Builder - Caluclate Value

$
0
0
Hello All

I'm using the Calculate Value Tool within Model Builder to take a user variable (a date) to create a where clause to apply as the Expression on a Make Query Table. Please see below the values I've used for my Calculate Value Tool.

When I run the model I'm getting the following error:

ERROR 000539: Error running expression: x(str(Start_Date)) <type 'exceptions.NameError'>: name 'Start_Date' is not defined
Failed to execute (CalcQueryWhere).

It looks to me that the Python script is not receiving the user variable as intended. Can any body help me with this? I really hope so, it would be very much appreciated.


Regards

Chris Mathtews



Expression:
x("Start_Date")

Code Block:
def x(Start_Date):
strDay = Start_Date[:2]
strMonth = Start_Date[2:-4]
strFYear = Start_Date[-4:]

intTYear = int(strFYear) + 2
strTYear = str(intTYear)

strFromDate = "'" + strFYear + "-" + strDay + "-" + strMonth + "'"
strToDate = "'" + strTYear + "-" + strDay + "-" + strMonth + "'"

strWhere = "qryELM.elmPK = tblELM.elmPK AND dbo.tblELM.LoggedDate >= " + strFromDate + " AND dbo.tblELM.LoggedDate <= DATEADD(year, 1," + strToDate + ") AND dbo.tblELM.EnquiryFK IN (4,22,25,61)"
return strWhere

Data type:
String

Viewing all articles
Browse latest Browse all 2485

Trending Articles