updated sql and proc