Jolly Priya

Jolly Priya

  • NA
  • 16
  • 13.2k

how to add computed columns in sql??

Jun 5 2013 2:52 AM


How to add two computed columns in sql ??
 I am using visual studio 2010 ,where i have created the database by using server explorer.Now i want to add two columns which are already computed.
e.g
i have columns like

so i want deduction should be pf+it+medicalallwnceded where pf  is computed column as 0.25* salary
i m getting error :Unable to modify table. 
Computed column 'pf' in table 'Tmp_ps' is not allowed to be used in another computed-column definition. where ps is the table name.
also i tried by using function
 my function is:
CREATE FUNCTION [dbo].[deduction](@pf Float ,@it Float , @medicalallwnceded Float )
  RETURNS FLOAT
  AS
BEGIN
DECLARE @deduction Float

SET @deduction = @pf + @it + @medicalallwnceded

RETURN

@deduction

END
where i m getting error like - Unable to modify table. 
Must declare the scalar variable "@pf".

Answers (2)