How to execute different queries depending on Custom variable value

You can follow this detailed document on how to to execute different query with custom variable value