CSD compatibility fix

Added the checks in SQL for the third state.