I creating a function and I have a red error line under the BEGIN keyword and I can't figure out what is wrong with this query?
USE PR
GO
CREATE FUNCTION fnInsCosts
(@NoDependents int)
RETURNS TABLE
BEGIN
RETURN
(SELECT
EmpName,
SUM(BaseCost) AS TotBaseCost,
SUM(SpouseIns) AS TotSpouseCost,
SUM(DepIns) AS TotDepCost,
SUM(DentalCost) AS TotDentalCost,
SUM(SUM(BaseCost) + SUM(SpouseIns) + SUM(DepIns) + SUM(DentalCost)) AS TotalInsCost
FROM
vwPayroll
WHERE
Dependants = @NoDependents
GROUP BY
EmpName)
END;
CREATE FUNCTION dbo.fnInsCosts- including when you're calling them