What version of Kentico are you on?
Where is this query being used?
They added a security feature to prevent this in 9.43 i think, but you used to be able to stick a ##WHERE## macro in the select and then in the where field on the webpart add your macro.