Based on this question, I've created a function and added it to my database. Now I want to use that function as a calculated column:
-- Based on https://stackoverflow.com/a/1012802/10406502 (work by Even Mien)
CREATE FUNCTION [dbo].[StripCharacters]
(
    @String NVARCHAR(MAX), 
    @MatchExpression VARCHAR(255)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
    SET @MatchExpression =  '%['+@MatchExpression+']%'
    WHILE PatIndex(@MatchExpression, @String) > 0
        SET @String = Stuff(@String, PatIndex(@MatchExpression, @String), 1, '')
    RETURN @String
END
GO
-- Table
CREATE TABLE [dbo].[Trailer]
(
    [ID] INT NOT NULL PRIMARY KEY IDENTITY,
    [ID_Hauler] INT NULL,
    [RegistrationNumber] NCHAR(9) NOT NULL,
    [RegistrationNumberSimplified] AS [dbo].StripCharacters([RegistrationNumber], '^A-Z0-9'),
    [MaxLoad] FLOAT NULL,
    CONSTRAINT [FK_Hauler_Trailer] FOREIGN KEY ([ID_Hauler]) REFERENCES [Hauler]([ID]),
    CONSTRAINT [UC_RegistrationNumber] UNIQUE ([RegistrationNumberSimplified])
)
However, the line where I reference the function throws an error:
"Berechnete Spalte: [dbo].[Trailer].[RegistrationNumberSimplified]" enthält einen nicht aufgelösten Verweis auf ein Objekt. Entweder ist das Objekt nicht vorhanden, oder der Verweis ist mehrdeutig, da er auf die folgenden Objekte verweisen könnte: [dbo].[StripCharacters] oder [dbo].[Trailer].[dbo]::[StripCharacters].
"Either the object doesn't exist, or the reference is ambigious, because it could mean either [dbo].[StripCharacter] or [dbo].[Trailer].[dbo]::[StripCharacter]."
I've also tried to let the server guess the namespace of the function. In that case, the database throws an error:
(57,1): SQL72014: .Net SqlClient Data Provider: Meldung 195, Ebene 15, Status 10, Zeile 11 'StripCharacters' is not a recognized built-in function name.
What's the problem here?
I also found this question, but the answer doesn't help me, because I don't use database references.
 
    