SQL Server Error 1075: Fix Scalar Function Returns
In this article
SQL Server error 1075 means a scalar-valued function contains a RETURN statement without a value, or a RETURN followed by a query. Scalar functions must return a single value using RETURN @variable or RETURN (expression). Fix it by replacing RETURN with RETURN @result, or by converting the function to a table-valued function if it needs to return rows.
What You'll Need
- SQL Server Management Studio (SSMS) or Azure Data Studio connected to your database.
- Permission to view and alter the function definition (ALTER permission on the schema, or db_owner).
- The name of the function and its schema. If you only know the error message, you can find it in Object Explorer or with a query against
sys.objects.
Step-by-Step
- Locate the function. In SSMS, expand your database, then Programmability > Functions > Scalar-valued Functions. If you are not sure which function is failing, run:
SELECT SCHEMA_NAME(schema_id) AS SchemaName, name FROM sys.objects WHERE type = 'FN';
This lists scalar functions. The error may also include the function name in the message text. - Open the function definition. Right-click the function and choose Script as > ALTER To > New Query Editor Window. Menu labels can differ slightly by SSMS version, but the Script as path is stable. Alternatively, use
sp_helptext 'schema.functionname'. - Find every RETURN statement. Search the definition for
RETURN. In a scalar function, each return path must supply a value. Look for bareRETURN;,RETURNat the end of a batch, orRETURN SELECT .... - Replace bare RETURN with a value return. Declare a variable at the top of the function body, assign it in your logic, and return it. For example:
DECLARE @Result int;SET @Result = ...;RETURN @Result;
If the function already computes a value, you can return the expression directly:RETURN (@Price * @Qty); - Remove any query after RETURN. A scalar function cannot end with
RETURN (SELECT ...). If you need to return a value from a query, assign it first:SELECT @Result = ColumnName FROM ... WHERE ...;thenRETURN @Result;. Make sure the query returns at most one row, or use an aggregate such asMAX. - Check all code paths return a value. If your function has
IF ... RETURN @A; ELSE RETURN @B;, every branch must return. A missing ELSE that falls through to the end without a RETURN also triggers error 1075. Add a finalRETURN @Default;as a safety net. - Consider a table-valued function instead. If the function is meant to return multiple rows or a result set, it should be an inline table-valued function (ITVF) or multi-statement table-valued function (MSTVF). Scalar functions return exactly one value. Convert the definition to
CREATE FUNCTION ... RETURNS TABLE AS RETURN (SELECT ...)for an ITVF. - Apply the change. Execute the ALTER statement. If you get a different error, read it carefully; syntax errors near RETURN often point to a missing semicolon or an unclosed BEGIN/END block.
- Test the function. Run
SELECT schema.functionname(args);with sample inputs. Verify it returns a single scalar value and does not error. Also test edge cases such as NULL inputs or empty tables.
Common Mistakes
- Using RETURN without a value in a scalar function. This is the direct cause of error 1075. Even
RETURN;with a semicolon is invalid in a scalar function. - Putting a SELECT after RETURN.
RETURN SELECT * FROM ...is not allowed in scalar functions. Assign to a variable first. - Forgetting a return path. An IF block without an ELSE that falls through to the end of the function will fail. Always include a final RETURN.
- Confusing scalar and table-valued functions. If you need rows, use a table-valued function. Scalar functions are for single values.
- Editing the wrong function. If multiple functions have similar names, confirm the schema and object ID before altering.
Tips
- Use
SET NOCOUNT ON;at the start of the function body to avoid extra result sets, though this does not affect error 1075. - Keep scalar functions simple. Complex logic with many branches increases the chance of a missing return path.
- When converting to a table-valued function, inline TVFs often perform better than multi-statement TVFs.
- Use
OBJECT_DEFINITION(OBJECT_ID('schema.functionname'))to quickly view the definition without scripting. - After fixing, run a quick test with
SELECT dbo.YourFunction(1);to confirm it works.
Troubleshooting
If you still see error 1075 after editing, check for hidden RETURN statements inside nested BEGIN/END blocks or inside TRY/CATCH blocks. A CATCH block that ends with RETURN; will also trigger the error. Ensure every RETURN in every block supplies a value.
If the error mentions a different line number, the problem may be a syntax error earlier in the definition that causes the parser to misinterpret RETURN. Check for missing semicolons, unmatched parentheses, or unclosed quotes.
If you cannot alter the function because it is schema-bound or referenced by other objects, you may need to drop and recreate it, or use ALTER FUNCTION with the WITH SCHEMABINDING option removed. Dropping a function can break dependent objects; script them first.
If the function is encrypted (WITH ENCRYPTION), you cannot view or alter its definition. You will need to recreate it from source control or a backup. Error 1075 on an encrypted function usually means you must replace it entirely.
If you are working in Azure SQL Database or Azure Synapse, the same rules apply. Use the Azure portal query editor or SSMS to alter the function.
Frequently Asked Questions
What exactly causes SQL Server error 1075?
A scalar-valued function contains a RETURN statement that does not include a value, or a RETURN followed by a query. Scalar functions must return a single value.
Can I use RETURN without a value in a table-valued function?
No. Table-valued functions use RETURN only in inline TVFs to return a SELECT statement. Multi-statement TVFs use RETURN without a value only to exit early, but they must still return a table variable. Error 1075 specifically applies to scalar functions.
How do I find which function is causing error 1075?
The error message often includes the function name. If not, check the SQL Server error log or run a query against sys.objects to list scalar functions, then review each definition for bare RETURN statements.
Can I fix error 1075 without dropping the function?
Yes. Use ALTER FUNCTION to modify the definition in place. Dropping is only necessary if the function is encrypted or schema-bound in a way that prevents alteration.
What is the difference between scalar and table-valued functions?
Scalar functions return a single value (int, varchar, etc.). Table-valued functions return a table. If your logic needs to return rows, use a table-valued function.
Does error 1075 occur in SQL Server 2019 and later?
Yes. The rule that scalar functions must return a value has been enforced across SQL Server versions. The error number and message are consistent.