Updated sql to support ESInputTag