Cannot create %S_MSG on view '%.*ls'. The function '%s' yields nondeterministic results. Use a deterministic system function, or modify the user-defined function to return deterministic results.

Error Message:
Msg 1949, Level 16, State 1, Line 2
Cannot create %S_MSG on view ‘%.*ls’. The function ‘%s’ yields nondeterministic results. Use a deterministic system function, or modify the user-defined function to return deterministic results.

Severity level:
16.

Description:
This error message appears when you try to create an indexed view that contains a nondeterministic function.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Error of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. The nondeterministaic function must be removed or replaced by a deterministic one.

Versions:
All versions of SQL Server /(beginning with SQL Server 2000).

Example(s):
USE Northwind;
GO

SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING,
    ANSI_WARNINGS,
    CONCAT_NULL_YIELDS_NULL,
    ARITHABORT,
    QUOTED_IDENTIFIER,
    ANSI_NULLS ON;
GO

IF OBJECT_ID (‘dbo.MyOrderView’, ‘View’) > 0
   DROP VIEW dbo.MyOrderView;
GO
CREATE VIEW dbo.MyOrderView
WITH SCHEMABINDING
AS
SELECT SUM(UnitPrice*Quantity*(1.00-Discount))* RAND() AS Revenue,
    OrderDate, ProductID, COUNT_BIG(*) AS MyCount
  FROM dbo.[Order Details] AS od
  JOIN dbo.Orders AS o
    ON od.OrderID = o.OrderID
 GROUP BY OrderDate, ProductID;
GO

CREATE UNIQUE CLUSTERED INDEX cix_MyOrderView
    ON dbo.MyOrderView (OrderDate, ProductID);
GO

Remarks:
In the above example we try to index the view MyOrderView. Because this view contains the RAND() function, the error is raised.

]]>

Leave a comment

Your email address will not be published.