You just need to create it with schemabinding
.
SQL Server will then verify whether or not it meets the criteria to be considered as deterministic (which it does as it doesn’t access any external tables or use non deterministic functions such as getdate()
).
You can verify that it worked with
SELECT OBJECTPROPERTY(OBJECT_ID('[dbo].[FullNameLastFirst]'), 'IsDeterministic')
Adding the schemabinding option to your original code works fine but a slightly simpler version would be.
CREATE FUNCTION [dbo].[FullNameLastFirst] (@IsPerson BIT,
@LastName NVARCHAR(100),
@FirstName NVARCHAR(100))
RETURNS NVARCHAR(201)
WITH SCHEMABINDING
AS
BEGIN
RETURN CASE
WHEN @IsPerson = 0
OR @FirstName="" THEN @LastName
ELSE @LastName + ' ' + @FirstName
END
END