Troubleshooting Guide: SQL Server Error 1075 — “RETURN Statements in Scalar Valued Functions Must Include an Argument”
Why This Error Happens
This error occurs because SQL Server’s T-SQL syntax rules require every scalar-valued function (SVF) to explicitly return a value of the declared return type via the RETURN statement. This is a compile-time parsing error (Error 1075), not a permissions or connectivity issue — it is triggered when a developer writes RETURN; with no expression, or omits the RETURN statement entirely on a code path inside a CREATE FUNCTION / ALTER FUNCTION block. Because scalar functions must always produce a single typed value, the SQL Server 2025 query parser rejects the object creation/compilation before it is ever registered in the database engine.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Function Definition
- Open SQL Server Management Studio (SSMS) or Azure Data Studio connected to your Windows Server 2025 / Windows 11 instance.
- Locate the exact
CREATE FUNCTIONorALTER FUNCTIONscript that failed — the error message in the Messages pane will reference the line number of the badRETURNstatement. - Run
SELECT definition FROM sys.sql_modules WHERE object_id = OBJECT_ID('YourFunctionName');if the function partially exists and you need to inspect it.
Step 2: Correct the RETURN Statement Syntax
- Edit the function body so every
RETURNincludes a value matching the declaredRETURNSdata type, e.g.:
CREATE FUNCTION dbo.GetTotal (@OrderId INT)
RETURNS DECIMAL(10,2)
AS
BEGIN
DECLARE @Total DECIMAL(10,2);
SELECT @Total = SUM(LineTotal) FROM OrderDetails WHERE OrderId = @OrderId;
RETURN ISNULL(@Total, 0); -- must return a value, not just RETURN;
END
- Check all branching logic (
IF,WHILE,CASE) to ensure there is no code path that hits a bareRETURN;or falls through without hitting anyRETURNat all.
Step 3: Re-Deploy and Validate the Script
- Drop and recreate the function using
DROP FUNCTION IF EXISTS dbo.YourFunctionName;followed by the correctedCREATE FUNCTIONstatement. - Execute the script in a new query window to confirm it compiles with zero errors (Command completed successfully).
- If deploying via a DACPAC/SSDT project in Visual Studio on Windows 11, rebuild the project first to catch the same error locally before publishing to the SQL Server 2025 instance.
Step 4: Audit Related Functions for the Same Pattern
- Run a metadata search across the database to catch similar issues proactively:
SELECT o.name, m.definition
FROM sys.sql_modules m
JOIN sys.objects o ON m.object_id = o.object_id
WHERE o.type = 'FN' AND m.definition LIKE '%RETURN;%';
- Fix any additional functions flagged by this query using the same method as Step 2.
Alternative or Verification Steps
- Verify the fix by executing the function directly, e.g.,
SELECT dbo.GetTotal(1001);— a successful result set with no red error text confirms the function compiled and executes correctly. - If the function logic genuinely has no meaningful value to return on certain paths, use a multi-statement table-valued function (
RETURNS @ReturnTable TABLE (...)) instead of a scalar function, since table-valued functions do not require a typedRETURNexpression.