Not sure about that one.
You have access to creating views or stored procs in your SQL DB, correct?
I would move away fom the commands and create a view to use in the DB.
In the Enterprise Managee the GUI interface is relatively easy to use.
Expand your DB
Right click on the Views and select New View
This is a decent GUI interface to add tables, drag and drop your joins. Change them from inner to outer, plce conditions, add select criteria, etc.
it will write the SQL as you use the GUI.
You are suppose to be able to write case statements in the Column section although mine chokes on this option where as on my coworkers it is fine. Never worried about it as I can write those elsewhere.
Anyway this might be a better solution for you.
Is there any SQL DB folks nearby that can help you write this or teach you the interface?
Edited by DBlank - 14 Sep 2009 at 12:16pm