Search code examples
databasesql-server-2008t-sqlviewsqldatatypes

Is it possible to change the datatype of a column in a view?


Usually I run a script like this:

ALTER TABLE [TABLE]
ALTER COLUMN [Column] NVARCHAR(40);

The result is that the field in the table gets converted to nvarchar. But what is the syntax for doing the same thing for a view? Or is that even possible?


Solution

  • Sure

    CREATE VIEW AView
    AS
    SELECT CAST(title AS char(50))
    FROM titles
    

    So check out CAST and also CONVERT on the msdn pages for full info