Select to view content in your preferred language

Model Builder SQL Expression

6056
4
03-30-2016 02:12 PM
deleted-user-V6usQu8yPcp9
Deactivated User


I am trying to set up a tool to query based on a date range and secondary field

I have created three Variables that i have set up as  Parameters, Start Date, End Date, Customer_Code.

I have the customer code selecting correctly however i get an error when i include my date range.

(Date >= '%Start Date%' AND Date <='%End Date%') AND Customer_Code = '%Customer Code%'

This is the error i get

NEW_SELECTION "Customer_Code = '35' AND Date => '3/1/2016 3:33:02 PM'"

Start Time: Wed Mar 30 16:06:22 2016

ERROR 000358: Invalid expression

An invalid SQL statement was used.

An invalid SQL statement was used. [Customers_3_24_16]

An invalid SQL statement was used. [SELECT OBJECTID FROM Customers_3_24_16 WHERE Customer_Code = '35' AND Date => '3/1/2016 3:33:02 PM']

Failed to execute (Select Layer By Attribute).

Failed at Wed Mar 30 16:06:22 2016 (Elapsed Time: 0.00 seconds)

I think the issue is that when i apply a definition query my date values look as like this

Date = date '2016-03-01 00:10:00'

Thanks in advance for your help!

0 Kudos
4 Replies
WesMiller
Deactivated User

Dates are tough to work with, i suggest you use select by attribute to see the format the date query is looking for.

deleted-user-V6usQu8yPcp9
Deactivated User

I have my SQL expression going connected to a select by attributes i think the issue is the "Date = date '2016-03-01 00:10:00'"

not sure if this is an issue but i have underlined and made bold the part that might be stopping it from working

Date = date '2016-03-01 00: 00:00'

0 Kudos
WesMiller
Deactivated User

Check your error message I'm not sure you can use PM in the date field try using a date from a select by attribute Get Unique Values test

Date => '3/1/2016 3:33:02 PM'

curtvprice
MVP Esteemed Contributor

The biggest problem is that date-time formats are often format and database-specific. It looks in the help like Wes is correct that PM is not likely to work for most data sources.

SQL reference for query expressions used in ArcGIS—Help | ArcGIS for Desktop  (Working with date and...

The format you reference is correct for file geodatabase:

Datefield = date 'yyyy-mm-dd hh:mm:ss'