Question: In MySQL code: Write a stored function individualSalesUpTo that, given a salespersons identifier as first argument and two dates as second and third argument, respectively,
In MySQL code:
Write a stored function individualSalesUpTo that, given a salespersons identifier as first argument and two dates as second and third argument, respectively, returns as INTEGER the turnover (i.e. sales worth in pounds) of the specified salesperson between the specified first and second date, including the sales on both dates. If the specified salesperson does not exist the function must return -1. If the salesperson does exist but any of the two specified dates is not a valid date the function must return -2. Illegal dates include dates that do not follow the standard MySQL date format, dates with incorrect month or day values, e.g. 2017-12-88, dates where years are larger than 9999, and in particular 0000-00-00. If the second date is actually before the first date, the turnover to be returned is simply 0.
Then, Write a stored procedure setBonuses that, given a date as argument sets up the bonuses for all salespeople for the month of the given date as explained below. For instance, if the given date is 2016-09-08 then the bonuses are to be computed for September 2016. If the date is illegal the procedure should abort with an error and error message: PROCEDURE accountname.date does not exist where accountname is the name of the ITS account running the procedure, so when you run it this will be your account name. Illegal dates include dates that do not follow the standard MySQL date format, dates with incorrect month or day values, e.g. 2017-12-88, dates where years are larger than 9999, and in particular 0000-00-00. Please ensure that the execution is actually giving an error and that the error message is exactly as described here (otherwise testing will fail and you will lose marks). Note that you must not attempt to produce a string on the screen using a SELECT statement The bonuses for a particular month are set up as follows: if the monthly target of a salesperson is met or surpassed by their individual sales for that month and their bonus amount is currently zero then their bonus amount is set to 10 per cent of the difference between actual sales for this month and target sales. This difference is then rounded down to the nearest integer. If their current bonus is not zero then their bonus amount is set to 15 per cent of the difference between actual sales for this month and the target sales. Again, this difference is rounded down to the nearest integer. If the monthly target of a salesperson is met or surpassed by their individual sales for the given month, the bonus date is set to the last day of this month. Hint: Use MySQL function LAST DAY. If the monthly sales target has not been met the bonus amount is reset to zero. The bonus date remains unchanged in that case. There is one more requirement you need to implement (in cases where the procedure does not throw an error already): If there is any bonus date recorded in FW SalesPerson that is already in the month passed to the procedure as argument, or if there is a bonus date even later than that argument, the procedure should do nothing at all (in particular, it must not throw any error either). In this case one does know the procedure will have been run already successfully before.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
