Select to view content in your preferred language

Why is this SQL expression invalid?

989
3
12-16-2021 03:39 PM
ChrisCowin
Occasional Contributor

I'm upgrading a model that processes GPS Points. From the GPS device we can only get a table with every point, so I'm trying to create additional function that will go to the ultimate GDB and get the last date in the field "Start_Time" which is a date field. I achieve this by sorting by descending of this field and then "Get Field Value" from utilities into a date variable. Where I'm stuck is making the SQL expression using inline replacement to delete all the values that are lower than the variable I got from the server. However everything I've tried returns an error saying the expression is invalid.

Expressions I've tried based off this article:

Start_Time >= date %Last_Start_Date%
"Start_Time" >= date %Last_Start_Date%
Start_Time >= %Last_Start_Date%
"Start_Time" >= %Last_Start_Date%
Start_Time >= /'%Last_Start_Date%/'

 The value that the variable reports is:

2/12/2021 5:00:41 AM

 

I don't really know what else to try. Its really hard to understand why it doesn't work when the error just says it doesn't work.

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

What DB system are you on? That article references a few other formats for things like Oracle, Postgres, etc.

- Josh Carlson
Kendall County GIS
0 Kudos
ChrisCowin
Occasional Contributor

Just a regular old GDB, nothing fancy. I tried changing the variable to a string and then used:

Start_Time <= date '%Last_Start_Date%'

That seems to have worked, but think its a little odd I can't do that directly since its already in a date field.

0 Kudos
AYamaguchi_UGRWCD
Occasional Contributor

Still having this problem in 2025. @esriesri Plz fix! I'd like be able to use a date parameter without needing the SQL editor.

Thanks so much @ChrisCowin for the workaround!

 

Specific use case was: In Model Builder, using the Select tool where one of the selection criteria was [DateColumn] >= [user-defined, single-value parameter]

 

The only thing I could think of that might cause issue was that:

[DateColumn] has the format 'dd-MMM-yy hh:mm:ss.sss',

[user-defined parameter] could only be entered as 'dd-MMM-yy hh:mm:ss' when (data type=date)

(the trailing milliseconds were omitted). Wondering if the discrepancy in data format is what caused the issue?

0 Kudos