Changed the SP materialize
implemented the sp code