Using Data Merge... no. It wasn't designed to be a database query result parser, but rather was designed to plonk information where a formfield appears. It doesn't have "triggers" as such like if-else statements.
Try this thread for a sample script: http://forums.adobe.com/message/4119515
I have a very similar project in mind for a client and am trying to figure out how to best research this. I'm struggling to even use the right terms to find discussion threads. This is the first one I have come across that comes very close. My client wants to have a bunch of documents available for a proposal, then have a window where he checks the documents he wants to use and the order they should appear. I imagine some of those documents will need to be created prior to this process or a window would allow them to fill in the variable data...client info, etc. I was thinking a more rudimentary way would be to build all the chapters and optional files out organizing them well in folders, then just using Acrobat to choose and combine the files, ordering them as needed. I guess that's my back-up plan, but would love more input/suggestions on how to be more dynamic within InDesign itself.
after some detective-work, i think i've found what both posters are after... it's a PDF from a presentation given to the Brisbane Adobe Users Group by one of their contributors. The presentation is at the bottom of this URL link: http://www.indesignusergroup.com/chapters/brisbane/events/1911/summary/
the PDF contains screen-shots of what I think both posters are after, but does not contain the actual scripts. However, the author has given his contact details on the URL.
Thanks so much!
Sent from my mobile