Cursor Sql Statement With If Condition