Avatar of Mr_Bach
Mr_Bach
 asked on

Alter Column Formula.

Please help me! I want to change column formula
Now my column formula is: (CONVERT([decimal](15,2),[Casting Internal Sales - Casting Unit Price]*(0.6),(0)))

but I want to change it to: (CONVERT([decimal](15,2),[Casting Internal Sales - Casting Unit Price]*(0.7),(0)))

I don't want to use SQL Studio Management, I want to use alter statement.

How can I do?
Microsoft SQL Server

Avatar of undefined
Last Comment
Raja Jegan R

8/22/2022 - Mon
David Todd

hi,

alter table dbo.MyTableName
  drop myColumnName

alter table dbo.MyTableName
  add myColumnName as (CONVERT([decimal](15,2),[Casting Internal Sales - Casting Unit Price]*(0.7),(0)))

http://technet.microsoft.com/en-us/library/aa275462(SQL.80).aspx

HTH
  David

PS Computed columns are great, but having to change the column definition frequently isn't that great. Are the other ways you could do this wihtout a computed column? Or is this change a one-off?
David Todd

PS Cant alter computed columns

>>
The altered column cannot be:
A computed column or used in a computed column.
<<


Mr_Bach

ASKER
I did as you said but I got this error:

Msg 3728, Level 16, State 1, Line 1
'Inventory Envaluation - As Cast' is not a constraint.
Msg 3727, Level 16, State 0, Line 1
Could not drop constraint. See previous errors.

And this is my codes:

alter table Main
  drop [Inventory Envaluation - As Cast]
alter table Main
  add [Inventory Envaluation - As Cast] as (CONVERT([decimal](15,2),[Casting Internal Sales - Casting Unit Price]*(0.7),(0)))
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Raja Jegan R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.