BUG: Msg 170 While Creating View with * and an Expression (164169)



The information in this article applies to:

  • Microsoft SQL Server 6.5

This article was previously published under Q164169
BUG #: 16594 (NT: 6.50)

SYMPTOMS

A CREATE VIEW statement fails with the following error message:
Msg 170, Level 15, State 1
Line%d: Incorrect syntax near ','.

This problem occurs if the select statement is something similar to either of the following:
  • Select *,<column_heading> = <expression> from <table name>

    -or-
  • Select *,<expression> <column_heading> from <table name>
where <expression> can be a column name, constant, function, or any combination of column names, constants, and functions connected by one or more operators, a CASE expression, or a subquery that returns one row.

WORKAROUND

To work around this problem, do either of the following
  • Qualify * with the table name.

    For example, use statements similar to the following:
          create view testview as
          select authors.*, today_date = getdate() from authors
    
    						
    -or-
  • Instead of using * to select all the columns, specify all the columns by names separated by commas.

    For example, use statements similar to the following:
          create view testview as
          select au_id, au_lname, au_fname, phone, address, city, state, zip,
          contract, today_date = getdate() from authors
    
    						

STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

This problem is only occurs with the CREATE VIEW statement. The same select statement works fine inside a stored procedure, a trigger, or when run alone.

Modification Type:MajorLast Reviewed:10/3/2003
Keywords:kbBug kbusage KB164169