How can I alter this computed column in SQL Server 2008?

André Miranda picture André Miranda · Mar 3, 2010 · Viewed 80.8k times · Source

I have a computed column created with the following line:

alter table tbPedidos 
add restricoes as (cast(case when restricaoLicenca = 1 or restricaoLote = 1 then 1 else 0 end as bit))

But, now I need to change this column for something like:

alter table tbPedidos 
alter column restricoes as (cast(case when restricaoLicenca = 1 or restricaoLote = 1 or restricaoValor = 1 then 1 else 0 end as bit))

But it's not working. I'm trying to input another condition to the case statement, but it's not working.

Thanks a lot!

Answer

Leniel Maccaferri picture Leniel Maccaferri · Oct 1, 2012

Something like this:

ALTER TABLE dbo.MyTable
DROP COLUMN OldComputedColumn

ALTER TABLE dbo.MyTable
ADD OldComputedColumn AS OtherColumn + 10

Source