Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Computed column 'the_column' in table 'the_table' cannot be persisted because the column is non-deterministic

$
0
0

I am getting the following error when trying to create a table with computed column that points to a function:Computed column 'JobNumber' in table 'SB_B_JobT' cannot be persisted because the column is non-deterministic.

Can anybody tell me if there is a work around for this issue. Please note that I have tried CAST and CONVERT on the computed column. Also have tried SchemaBinding.

Here are my scripts

--Sample sequence object
    CREATE SEQUENCE JobNumber_1_1
    AS bigint
        START WITH 1
        INCREMENT BY 1 ;
    GO

    CREATE FUNCTION dbo.GetNextJobNumber(@companyId bigint, @branchId bigint)
    RETURNS bigint
    AS
    BEGIN
 DECLARE @nextNumber bigint
 DECLARE @sqlStatment nvarchar(1000)

 SET @sqlStatment = N'SELECT @nextNumber = NEXT VALUE FOR JobNumber_' + CONVERT(varchar(5), @companyId) + '_' + CONVERT(varchar(5), @branchId)

 EXEC SP_EXECUTESQL @sqlStatment, N'@nextNumber bigint OUTPUT', @nextNumber OUTPUT

 RETURN (CONVERT(bigint, @nextNumber))
    END
    GO


    --Create table script that is not working
    CREATE TABLE dbo.SB_B_JobT
    (
          Id int IDENTITY (1,1) NOT NULL,
 CompanyId bigint,
 BranchId bigint,
 JobNumber AS dbo.GetNextJobNumber(CompanyId, BranchId) PERSISTED
    )


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>