Computed column 'Full_Output' in table 'CL_Register' is not allowed to be used in another computed-column definition.

ravi kumar 331 Reputation points
2020-10-06T04:29:49.12+00:00

hello all ,

I am new to MSSQL , and i am facing this error while creating a computed column ,

here is the query for first computed column:

ALTER TABLE dbo.CL_Register DROP COLUMN Full_Output
;
GO
ALTER TABLE dbo.CL_Register ADD Full_Output AS (Speed_mpm * 1440)
;

here is the query for second computed column:

ALTER TABLE dbo.CL_Register ADD Efficiency AS ((Output_Qty_Mtrs*100)/Full_Output)
;

"i want to store these values physically in my table", kindly help me.

Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. MelissaMa-MSFT 24,221 Reputation points
    2020-10-06T05:16:46.927+00:00

    Hi @ravi kumar ,

    A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a subquery.

    You could refer Computed Columns.

    A computed column cannot reference another computed column. You have these options:

    1. Create a second computed column that includes the same logic as the first computed column (which cannot be referenced).
    2. Replace the first computed column with an ordinary column.
    3. Create a VIEW on top of the table and implement your second column in it:

    In your situation, you could try with second point as below:

     ALTER TABLE dbo.CL_Register ADD Efficiency AS ((Output_Qty_Mtrs*100)/(Speed_mpm * 1440));  
    

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.