How to convert a fixed column to a computed column?

  • Hi,

    I have an already existing table say TABLE1 with some records, it have a column say COL1 VARCHAR(1) NOT NULL having values Y or N. I want to convert this Fixed Column to Computed Column on certain criteria say (CASE WHEN ISNULL([END_DATE], GETDATE()) >= GETDATE() THEN 'Y' ELSE 'N' END).

    Please help!!!!

    Sumit Rastogi

  • You'd need to drop the existing column then create the computed one.

    Computed columns can't be created/modified through an alter column statement (the same goes for if you change the definition of a existing computed column)

  • Hi

    you can not convert existing column with computed expression.You can add new column as Computed one in a existing table.

    Thanks,

    Naginder

  • Thanks for the reply....

    That I know thats why I already describe in the question that the table already have some records (say about .2 millions) so I think dropping is not a good idea.

    Sumit

  • You could rename the old column to something else using sp_rename, then create the computed column. Either way you're going to want to drop the existing column at some point

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply