0
I need to create a user role (user function
) which receives as input parameters a store identifier code and a category identifier code and returns as a result an integer value that informs the amount (sum) of
all products offered by the shop belonging to this category.
What I tried was this code here:
BEGIN
DECLARE resultadoSoma int;
SELECT SUM(produto.idProduto) AS idProduto INTO resultadoSoma FROM produto
WHERE produto.idLoja = IdLoja AND produto.idCategoria = IdCategoria;
RETURN resultadoSoma;
END
I tried to put the sum function to add the product table ID. The bank even accepted this operation, but it is not adding up the correct way (logic error, not syntax). Could you help me?
If you want to know the quantity, the correct function will be
count()
instead of theSUM
. The SUM is used to add up the values and it makes no sense to add up the values of the ID field. Noselect
you need to use theIdLoja
and theIdCategoria
as parameter.CREATE FUNCTION...
and the query, what result is receiving and what result is waiting?– Clarck Maciel