Home Forums SQL Server 7,2000 T-SQL Creating Views: Changing column names RE: Creating Views: Changing column names

  • Dennis,

    try this:

    IF EXISTS (SELECT TABLE_NAME

        FROM   INFORMATION_SCHEMA.VIEWS

        WHERE  TABLE_NAME = N'Spain_Orders')

        DROP VIEW Spain_Orders

    GO

    CREATE VIEW Spain_Orders

    AS

     SELECT

     [Order ID],

     [Customer],

     [Employee],

     [Order Date],

     [Required Date],

     [Shipped Date],

     [Ship Via],

     [Freight],

     [Ship Name],

     [Ship Address],

     [Ship City],

     [Ship Region],

     [Ship Postal Code],

     [Ship Country] as [DestinationSpain]

     FROM Orders

     WHERE [Ship Country] = 'Spain'

    GO

    to change a colum name, you need to use an alias for that column name. The syntax is allowed in the SELECT statement: ... ColumnName As AliasName

    By the way, you could this the alias as the heading of the column in the SELECT statement or by creating the view as you want to do.

     

    Ben Lopez