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

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


Sure

CREATE VIEW AViewASSELECT CAST(title AS char(50))FROM titles

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


Yes..You can try Convert function to do this.

Convert (Desired datatype,column name)

eg.Convert(varchar(50),dbo.User_master.User_email)where User_email has previous type as nvarchar(MAX).

If you want to convert nvarchar data to datetime then additional parameter is needed to Convert function like

CONVERT(data_type(length),expression,style)

eg. Convert(Datetime,dbo.User_master.User_DOB,103)

more info at SQL Server CONVERT() Function


If you have updated the type in the table and the view still reflects the old type, simply running an alter view without changing anything will update the type