Conslidating sql calls