Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make a deterministic FullName scalar-valued function in SQL Server?
    primarykey
    data
    text
    <p>I have the following scalar-valued function defined in a SQL-Server 2008 database:</p> <pre class="lang-sql prettyprint-override"><code>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) &gt; 0 BEGIN IF LEN(@result) &gt; 0 BEGIN SET @result += N' ' END SET @result += @firstName END IF LEN(@middleName) &gt; 0 BEGIN IF LEN(@result) &gt; 0 BEGIN SET @result += N' ' END SET @result += @middleName END IF LEN(@lastName) &gt; 0 BEGIN IF LEN(@result) &gt; 0 BEGIN SET @result += N' ' END SET @result += @lastName END IF LEN(@suffix) &gt; 0 BEGIN IF LEN(@result) &gt; 0 BEGIN SET @result += N', ' END SET @result += @suffix END RETURN @result END </code></pre> <p>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:</p> <pre><code>'Members' table - Unable to modify table. Computed column 'FullName' in table 'Tmp_Members' cannot be persisted because the column is non-deterministic. </code></pre> <p>I can create a non-persisted computed column no problem. Here's an abridged schema for my table:</p> <pre class="lang-sql prettyprint-override"><code>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] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload