Select to view content in your preferred language

Query.where Syntax

1139
6
11-15-2010 07:17 AM
WesBailes
Occasional Contributor
I am trying to implement a DISTINCT query.  Is this method supported?  Can't seem to get it to work.  Here is my current syntax: 

query.where = "DISTINCT Map WHERE DISTRICT= '" + strDistrict + "'" 

Is there any documentation on query syntax for map services (or feature services).  Thanks for any suggestions!
Tags (2)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus
Wes,

   No that is not supported. What you are attempting to do is specify a SELECT statement and all you are allowed to do is specify the WHERE portion of the SELECT statement as the property alludes to.
0 Kudos
WesBailes
Occasional Contributor
Thanks Robert!  Kind of what I figured.  I found a workaround for my situation that seems to work fine.
0 Kudos
DavidSavory1
New Contributor
Hi Wes,

I have a need to do same thing and was hoping to find an elegant solution.  I was planning on developing a post query algorithm to find the unique values.  Would you mind sharing your solution.

Thanks,
David Savory
0 Kudos
WesBailes
Occasional Contributor
Hi Wes,

I have a need to do same thing and was hoping to find an elegant solution.  I was planning on developing a post query algorithm to find the unique values.  Would you mind sharing your solution.

Thanks,
David Savory


In this scenario I am attempting to find the distinct Map within the query.  You will need an ArrayList or ArrayCollection declared somewhere (mapsAL).

function onResult(featureSet:FeatureSet, token:Object = null):void
        {
             var i:int = 1;
             var j:int=0;
             var item:String;
             var sortAttr:Array;
  
             sortAttr=featureSet.attributes.sortOn("Map");
             //loop to add unique Map values to the mapsAL array list
             for (j=0; j<featureSet.attributes.length-1; j++)
                 {
                       item = sortAttr.Map;
                       //getItemIndex returns -1 it item is not found in the array
                       i=mapsAL.getItemIndex(item);
                       if (i==-1){
                       mapsAL.addItem(item);
                  }
        }
0 Kudos
MayJeff
Deactivated User
I try to get unique value on my query combo box.  Without if statement there are no errors, but just got same value on the combo box. 
(TypeError: Error #1006: getItemIndex is not a function.
at querycombo/private:init/onResult())


See code below:

             function onResult(featureSet:FeatureSet, token:Object = null):void
                {
                 var StArr:Array = [];
                 for each (var myGra:Graphic in featureSet.features)
                 {
                 //if (StArr.getItemIndex(myGra.attributes["township"].toString()) == -1 )
  // {
  StArr.push(myGra.attributes["township"].toString());
  // }
                 }
                 StArr.sort();
                 StCb.dataProvider = StArr;
                }

Thank you.
0 Kudos
WesBailes
Occasional Contributor
I try to get unique value on my query combo box.  Without if statement there are no errors, but just got same value on the combo box. 
(TypeError: Error #1006: getItemIndex is not a function.
at querycombo/private:init/onResult())


See code below:

             function onResult(featureSet:FeatureSet, token:Object = null):void
                {
                 var StArr:Array = [];
                 for each (var myGra:Graphic in featureSet.features)
                 {
                 //if (StArr.getItemIndex(myGra.attributes["township"].toString()) == -1 )
  // {
  StArr.push(myGra.attributes["township"].toString());
  // }
                 }
                 StArr.sort();
                 StCb.dataProvider = StArr;
                }

Thank you.


You are getting the error due to the fact that .getItemIndex is not a member of the Array Class.  Use a ArrayList or ArrayCollection to store the values.
0 Kudos