Search code examples
sql-servert-sqlalter

T-SQL: Alter View


I have a view with a field for date as a varchar. I need to change it to date time using the following code

    CONVERT(DATETIME, MyDates)

This works fine when executing the view but I want to make the change permanent. I need some help with the syntax. So far I have

    ALTER VIEW tableName
    CONVERT(DATETIME, MyDates)

but it's obviously not working


Solution

  • A view only fetches the data from the table as per the query.So you cannot change the datatype of the view. you have to change it in table.