Converting column data type of SQL server view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alien
    New Member
    • Sep 2007
    • 61

    #1

    Converting column data type of SQL server view

    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
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can use either the cast or convert function.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      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

      Comment

      • swathee
        New Member
        • Dec 2013
        • 9

        #4
        Code:
        CREATE VIEW AView
        AS
        SELECT CAST(Name AS Varchar(50))
        FROM Table
        Last edited by Rabbit; Dec 9 '13, 05:14 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

        Comment

        Working...