By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Converting column data type of SQL server view

P: 61
Hi is it possible to change the column data type of a view in SQL server?

I have a view and would like to chance the data type from nvarchar to varchar.

Using SQL server 2008

Cheers
Oct 4 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,430
You can use either the cast or convert function.
Oct 4 '12 #2

ck9663
Expert 2.5K+
P: 2,878
A view is a saved T-SQL statement. It does not actually have a data nor structure. It will use the structure of the underlying base table or whatever the result of the query (if there are explicit or implicit changes). You can always force it to what data type you want through cast and convert function. Just be aware of some values that cannot be converted to a specific data type.

Happy Coding!!!


~~ CK
Oct 5 '12 #3

P: 9
Expand|Select|Wrap|Line Numbers
  1. CREATE VIEW AView
  2. AS
  3. SELECT CAST(Name AS Varchar(50))
  4. FROM Table
Dec 9 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.