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.

I use Definition Queries a lot in my daily GIS life, but one of the many things I've found annoying about ArcMap is the inability to comment out Definition Queries. I'd like to have this option as sometimes I want to turn on/off the Definition Query or I want to have multiple Queries on a single Shapefile, but only one active at a time.

So far to get around this, I usually just have a notepad document in the background and copy and paste as necessary. But the ideal solution would be to use the definition query tab in the layer properties to replace this document. I might have multiple different queries on a layer, but all commented out.

As I understand, Definition Queries are written in SQL. To comment in SQL I believe you either start a line with: -- or encompass a statement in brackets: { }. I've tried both of these:

Original: "DATA_AQUISITION" LIKE 'MISSING XSECTION'
Dashes:   --"DATA_AQUISITION" LIKE 'MISSING XSECTION'
Brackets: {"DATA_AQUISITION" LIKE 'MISSING XSECTION'}

The last two statements return a SQL expression error and won't draw in ArcMap. I'm not looking for a programming solution, as that would just be too much work.

Any help would be appreciated, thanks!

share|improve this question
1  
I don't have ArcGIS on this system to Check out, but does something like 'OR 1=1' or maybe even ObjectID>-1 work? –  Devdatta Tengshe Jan 4 '13 at 16:01
    
@DevdattaTengshe that does work too pretty much comment out a query: "OBJECTID" <> -1 OR "DATA_AQUISITION" LIKE 'MISSING XSECTION' That's a great solution, but I am looking for something that seems more like an actual comment out. Something that can be done in every language of code, where you have multiple query options on different lines and all but one are commented out. If its not possible, so be it, but I believe it would be a great option to have. –  Cody Brown Jan 4 '13 at 16:07
add comment

1 Answer 1

up vote 3 down vote accepted

Just a guess, but the reason commenting it out doesn't work is probably because a definition query is just the WHERE clause part of a larger SQL statement built internally by ArcGIS whenever it needs to query the underlying database, for example to draw the layer. When you add the comment characters, ArcGIS still adds the WHERE clause and the underlying DB freaks because it's not valid SQL.

On the Query Builder dialog there are load and save buttons. Save creates a .exp file that you can then load back in with the Load button. It's a few more clicks than you are probably looking for but it's something.

share|improve this answer
    
That's true that it's just part of a larger statement. It's very possible that the DB freaks when we add a comment, but I know it is possible in other programs that use SQL to add a comment in the middle of a statement. The saving and loading of a .exp is something I was using before, but like you said it is a few clicks more than I am looking for. I also am trying to reduce the amount of code and files attached to each MXD I have and that would instead increase it. –  Cody Brown Jan 4 '13 at 16:17
1  
SELECT * FROM table WHERE is not valid SQL is what I was getting at. There has to be something following the WHERE keyword, or the WHERE keyword needs to not be there at all. ArcGIS probably adds WHERE if there is anything at all in the Definition Query. –  blah238 Jan 4 '13 at 16:20
    
I tried SELECT * FROM table WHERE "OBJECTID" <> -1 --"DATA_AQUISITION" LIKE 'MISSING XSECTION' and SELECT * FROM table WHERE "OBJECTID" <> -1 {"DATA_AQUISITION" LIKE 'MISSING XSECTION'} Both result in the same errors. It has something following the WHERE, but still can't handle the comments. –  Cody Brown Jan 4 '13 at 16:22
1  
Huh. Well whatever the reason, clearly the commenting approach won't work. –  blah238 Jan 4 '13 at 18:13
1  
Actually, C-style commenting syntax looks like it works. Try this for example: 1 = 1 /*"DATA_AQUISITION" LIKE 'MISSING XSECTION'*/. Worked for me on Oracle. The 1 = 1 part is needed, using just the comment does not work (Missing Expression error). –  blah238 Jan 4 '13 at 18:30
show 1 more comment

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.