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!
A: There is NO way to alter computed column. You will have to drop and recreate it.
Answers. First remove the current computed column. Then add the new computed column (with same name.) Unfortunately, in order to change a computed column, you must DROP and re-CREATE the column.
How do you assign aname to a computed field? It is a field whose values you can derive from existing fields. By putting fieldName (operation:+,-,*,/) fieldName. You assign names by putting the word AS after the computation then puttingthe name you want to call it.
Something like this:
ALTER TABLE dbo.MyTable DROP COLUMN OldComputedColumn ALTER TABLE dbo.MyTable ADD OldComputedColumn AS OtherColumn + 10
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With