Sqlq Db2 Substring Sql Statement With If Condition In Python