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

后端 未结 2 1496
独厮守ぢ
独厮守ぢ 2021-01-01 17:19

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 c

相关标签:
2条回答
  • 2021-01-01 17:40

    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

    0 讨论(0)
  • 2021-01-01 17:54

    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

    0 讨论(0)
提交回复
热议问题