Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In ArcGIS Server 10, I am running queries against several fields in a feature class. All of them are sent with the format FIELDNAME ='value' (all queries contain the single quotes).

This is failing in cases where have numeric data. Is there any kind of setting I can use with the map service to allow me to query numeric data with strings?

share|improve this question
    
Are you using the REST API to do this? From what source and in what protocol/language are your queries? –  dmsnell Apr 8 '11 at 16:43
    
I am using the REST API and my data is stored in SQL Server 2008 R2. –  Seth P. Apr 8 '11 at 17:32
    
Do you have any error messages? I tried this and found that with single quotes it didn't matter whether or not it was numerical. I verified on double and integer types. One thing, however, is that when I used double quotes it did return no results, but it did so even when querying string and character data types. –  dmsnell Apr 11 '11 at 13:28
    
No error messages, I just don't get any results. –  Seth P. Apr 11 '11 at 17:46
    
Does it return "No results found." If it does, that means that the query has simply failed to find any matching items. If there is something wrong with the query, it should return another message, such as "Unable to perform query. Please check your parameters" Try using the web interface to perform a test REST query - arcgis/rest/services/map/MapServer/0/query?where=field='45'&returnGeometry=true&‌​outFields=name&f=html –  dmsnell Apr 12 '11 at 13:03

1 Answer 1

You need to cast the field to a varchar first:

CAST("FIELDNAME" as VARCHAR(20)) = '1'

May not work with all data sources, but SQL and FileGDB do work.

share|improve this answer
    
My thought is that you should build a proper query rather than adding CAST()s to your where clause. –  Derek Swingley Apr 8 '11 at 16:34
    
@Derek - I'd build the query properly too personally. However, his question is how to query numeric data with strings (which will result in less-than-ideal performance), which CAST will accomplish. He'll run into issues with knowing what size of VARCHAR to cast everything to though. –  Sasa Ivetic Apr 8 '11 at 16:39
    
good point, I think you nailed it then. –  Derek Swingley Apr 8 '11 at 16:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.