Select to view content in your preferred language

Query.where clause is a SQL language?

1669
1
Jump to solution
07-18-2017 12:23 PM
LindaM
by
Emerging Contributor

I am very confused about the Line 31, where clause is like below (ESRI JS API sample code):

query.where clause Sandbox 

The one that is used on Line 31 -- query.text = dom.byId("stateName").value; 

My quesion is: how can it know the ("stateName").value is compared to STATE_NAME, not other variable?   

Second question is that:  I would like to use  ---    query.where ="STATE_NAME =  stateName.value";  but it does not work at all; 

I know it should be:  query.where ="STATE_NAME = '" + dom.byId ("stateName.value") + "'"; 

But why the clause should be like that?

Another question is what should I go to study the grammar of query.where clause? SQL? The statement like below is too confusing: 

query.where = "POP04 > " + population;
query.where = "NAME = '" + stateName + "'"; 

Thanks!
1 Solution

Accepted Solutions
ThomasSolow
Frequent Contributor

It looks like there is a text parameter on queries to a MapServer, it's mentioned in the REST API documentation.

This will search for matches with the layer's display field, which happens to be STATE_NAME in this case.

To use where instead, you could do this similar to how you indicated.  You do need to wrap the value in single quotes.  Another option is to use the new JavaScript template strings to make this easier.  Note this uses backticks (`) as string delimiters: 

query.where = "STATE_NAME = '" + dom.byId("stateName").value + "'";‍‍
// OR
query.where = `STATE_NAME = '${dom.byId("stateName").value}'`

You can have multiple clauses separated by AND or OR.  I'm not sure where to find documentation about the SQL syntax that is accepted, although I seem to recall it being somewhere in the REST API documentation.  It can be quite difficult to find useful information there to be honest.

View solution in original post

1 Reply
ThomasSolow
Frequent Contributor

It looks like there is a text parameter on queries to a MapServer, it's mentioned in the REST API documentation.

This will search for matches with the layer's display field, which happens to be STATE_NAME in this case.

To use where instead, you could do this similar to how you indicated.  You do need to wrap the value in single quotes.  Another option is to use the new JavaScript template strings to make this easier.  Note this uses backticks (`) as string delimiters: 

query.where = "STATE_NAME = '" + dom.byId("stateName").value + "'";‍‍
// OR
query.where = `STATE_NAME = '${dom.byId("stateName").value}'`

You can have multiple clauses separated by AND or OR.  I'm not sure where to find documentation about the SQL syntax that is accepted, although I seem to recall it being somewhere in the REST API documentation.  It can be quite difficult to find useful information there to be honest.