我在 sql server 中编写了一个函数,并在“return”语句中遇到错误。
我面临的错误是
Incorrect syntax near 'RETURNS'.
我的sql函数如下
CREATE FUNCTION UTILIZATION(@START_DATE DATETIME,
@END_DATE DATETIME,
@D1 DECIMAL(5,2),
@D2 DECIMAL(5,2),
@D3 DECIMAL(5,2),
@D4 DECIMAL(5,2),
@D5 DECIMAL(5,2),
@D6 DECIMAL(5,2),
@D7 DECIMAL(5,2))
RETURNS DECIMAL(5,2)
AS
BEGIN
DECLARE
@UTILIZATION DECIMAL(5,2),
@TOTAL_HOURS DECIMAL(5,2),
@TOTAL_HOURS_ACCRUED DECIMAL(5,2),
@QUERY NVARCHAR(MAX);
BEGIN
SET @TOTAL_HOURS = @D1 + @D1 + @D3 + @D4 + @D5 + @D6 + @D7
SET @QUERY = ' SELECT TOTAL_ACTUAL_HOURS AS @TOTAL_HOURS_ACCRUED FROM WEEK_MASTER WHERE' +
' START_DATE = ' + '''' + @START_DATE + '''' +' AND ' +
' END_DATE = ' + '''' + @END_DATE + ''''
EXEC SP_EXECUTESQL @QUERY
SET @UTILIZATION = (@TOTAL_HOURS/@TOTAL_HOURS_ACCRUED)*100
RETURNS @UTILIZATION
END
END