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?
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?
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
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
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