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:
Great Solved my issue of temp table too.Me new to SQL
Great explanation & example! Thanks!!
Post a Comment