I am getting one error when I try to make my field IsPersisted=True
This is the definition of my table
CREATE TABLE [dbo].[AdvanceMST](
[AdvanceID] [bigint] IDENTITY(1,1) NOT NULL,
[AppliedDate] [datetime] NULL,
[ApprovedDate] [datetime] NULL,
[AdvanceStatus] [varchar](100) NULL,
[AdvanceFromEngineerID] [bigint] NULL,
[AdvanceToEngineerID] [bigint] NULL,
[AccountResourceID] [bigint] NULL,
[AdvanceAmount] [float] NULL,
[ApprovedAdvanceAmount] [float] NULL,
[POrderID] [bigint] NULL,
[SiteID] [bigint] NULL,
CONSTRAINT [PK_AdvanceMST] PRIMARY KEY CLUSTERED
(
[AdvanceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
This is the error message
Computed column ‘Month’ in table ‘Tmp_AdvanceMST’ cannot be persisted because the column is non-deterministic.
I am not able to understand what does this error message mean and how to solve this problem in order to make it IsPersisted=true
The
datenamefunction can return different results dependant on the language of the logged in user hence is not deterministic. Marking a computed column as persisted means SQL Server stores the results of the computation which requires there to be exactly one result.If you need this as persisted at all you can replace with a 12 branch
caseexpression with the specific language you want used.Although it would probably be all round better to have
month(AppliedDate)as a persisted integer column and have thedatenamefunction in a non persisted computed column.Edited to give example as per comments