Your select this with a syntax error, when you select to set the value of select in some variable ( SET @Total =) , you need to involve all select between parentheses SET @Total = (select campo from tabela), in your case you are closing the relationship before the from (SELECT SUM(ped.ValorPagar)), this last parenthesis has to be removed and inserted at the end of select.
create FUNCTION dbo.totalGastoPedido(@id_mesa int)
RETURNS int
AS
BEGIN
DECLARE @Total money
declare @Pedido table
(
IdMesa int,
ValorPagar numeric(18,2)
)
insert into @Pedido values
(1,122.32),
(1,12.32),
(1,2.32),
(4,1.32),
(5,2.32)
SET @Total = (SELECT SUM(ped.ValorPagar) -- removar o parenteses daqui e coloque no final da query
FROM @Pedido ped
where @id_mesa = IdMesa
--and ped.Data>'2016-02-10' and ped.Data<'2016-02-10' --- comentado para facilita na buscar
) -- Aqui....
RETURN @Total
END
Can you explain the question better? What’s the problem, what’s the mistake? What are you trying to do?
– Sergio
This is in sql server?
– rray
I’m sorry I didn’t write in full, I plan to make a Function that receives the Id from the table and returns the total spent from that table in a given period
– Alexandru
And yes it is SQL SERVER, I am begginer in sql server
– Alexandru
When having compile the error appears in FROM
– Alexandru
Edit the question, scan the error message, sql server tag tbm.
– rray
Msg 156, Level 15, State 1, Procedure totalGastoPedido, Line 7 Incorrect syntax near the keyword 'FROM'.
– Alexandru
@Alexandru can [Dit] the question and gather this information?
– Sergio