in reply to Dynamic query generation
Have you thought about TRIGGERS?
I may be missing the point slightly though.