CREATE FUNCTION TOTALGUSTAVOS () RETURNS @VALORES TABLE
(ID_USUARIO INT,VALORES REAL)
AS BEGIN
INSERT @VALORES
SELECT CA.ID_USUARIO,SUM(CA.QUANTIDADE * CO.VALOR) AS VALOR
FROM MOEDAS.CARTEIRA AS CA
INNER JOIN MOEDAS.COTACAO AS CO
ON CO.ID_MOEDA = CA.ID_MOEDA
WHERE CO.DATAHORA = (SELECT MAX(DATAHORA) FROM MOEDAS.COTACAO AS CO2
WHERE CO2.ID_MOEDA = CO.ID_MOEDA)
CREATE FUNCTION TOTALGUSTAVOS () RETURNS @VALORES TABLE (ID_USUARIO INT,VALORES REAL) AS BEGIN INSERT @VALORES SELECT CA.ID_USUARIO,SUM(CA.QUANTIDADE * CO.VALOR) AS VALOR FROM MOEDAS.CARTEIRA AS CA INNER JOIN MOEDAS.COTACAO AS CO ON CO.ID_MOEDA = CA.ID_MOEDA WHERE CO.DATAHORA = (SELECT MAX(DATAHORA) FROM MOEDAS.COTACAO AS CO2 WHERE CO2.ID_MOEDA = CO.ID_MOEDA)
END SELECT * FROM TOTALGUSTAVOS()