AnsweredAssumed Answered

Where clause syntax using field name coming from a join, setting a variable

Question asked by schlot on Apr 7, 2015
Latest reply on Apr 14, 2015 by schlot

This is for the where clause of a FeatureLayer.selectFeatures.


I have used a variable for a field name, but this is the first time I've tried to get this to work with a field name coming from a join to a SQL Server database table.  I know the single quote/double quote looks strange, but hard coded, this is the only way it works.   I assume this is because the field names from the join  contain %, so I needed to surround the field name with extra punctuation.


I started off with this and it works:




The database is different from test to production and I need to set some variables instead.


var whereClause = countyFieldName + " LIKE '%" + currentCounty + "%'"; 


This doesn't work.  When you put in a breakpoint, the syntax looks OK.  I'm using LIKE because DCOUNTY has trailing blanks in it and I have no control over this agency's database.


I would actually prefer to just set the variable as MCDS_DATAWAREHOUSE.EDAPPGISSCHLDIRT.%SCHOOL_DIRECTORY_DISTRICT, which is the database name and just concatenate the field names.   I have this set earlier for my infoTemplates.  I couldn't wrap my head around this:


var whereClause = distFieldName + ".DCOUNTY LIKE '%" + currentCounty + "%'";  


That's not quite right, because I need to punctuate the field name.