Mar 18, 2013

An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.


Suppose we have Customer table with following data:

CustID
Emp_Name
1
Scott
2
Greg
3
Davis

If we will execute following sql query:

SELECT
    CustID + 100,
    Emp_Name
INTO #Temp
FROM Customer

Or

SELECT
    CustID + 100 "",
    Emp_Name
INTO #Temp
FROM Customer

Or

SELECT
    CustID + 100 [],
    Emp_Name
INTO #Temp
FROM Customer

We will get error message:

An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.

Cause: In SELECT INTO statement, all columns in the select list must have column alias if it is sub query or derived column. And alias cannot be ''' or []

Solution:

Use columns alias in the derived column CustID + 100. For example:

SELECT
    CustID + 100 AS CustID,
    Emp_Name
INTO #Temp
FROM Customer

2 comments:

  1. Great Solved my issue of temp table too.Me new to SQL

    ReplyDelete
  2. Great explanation & example! Thanks!!

    ReplyDelete