I have the following scalar-valued function defined in a SQL-Server 2008 database:
CREATE FUNCTION FullName
(
@title nvarchar(50),
@firstName nvarchar(50),
@middleName nvarchar(50),
@lastName nvarchar(50),
@suffix nvarchar(50)
)
RETURNS nvarchar(300)
AS
BEGIN
DECLARE @result nvarchar(300) = @title
IF LEN(@firstName) > 0
BEGIN
IF LEN(@result) > 0
BEGIN
SET @result += N' '
END
SET @result += @firstName
END
IF LEN(@middleName) > 0
BEGIN
IF LEN(@result) > 0
BEGIN
SET @result += N' '
END
SET @result += @middleName
END
IF LEN(@lastName) > 0
BEGIN
IF LEN(@result) > 0
BEGIN
SET @result += N' '
END
SET @result += @lastName
END
IF LEN(@suffix) > 0
BEGIN
IF LEN(@result) > 0
BEGIN
SET @result += N', '
END
SET @result += @suffix
END
RETURN @result
END
I want to create a persisted computed column that is based on this function, but when I try to save the computed column, I get this error:
'Members' table
- Unable to modify table.
Computed column 'FullName' in table 'Tmp_Members' cannot be persisted because the column is non-deterministic.
I can create a non-persisted computed column no problem. Here's an abridged schema for my table:
CREATE TABLE [dbo].[Members](
[Id] [int] NOT NULL,
[Title] [nvarchar](50) NULL,
[FirstName] [nvarchar](50) NULL,
[MiddleName] [nvarchar](50) NULL,
[LastName] [nvarchar](50) NULL,
[Suffix] [nvarchar](50) NULL,
[FullName] AS ([dbo].[FullName]([Title],[FirstName],[MiddleName],[LastName],[Suffix])),
CONSTRAINT [PK_Members] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]