Though I have dropped the temporary table, it does not let me select the new column names if the temporary table with same table name with additional column names will be created.
I have been using SQL Server 2008.
Try this code for instance:
IF (object_id('tempdb..#xyz') IS NOT NULL)
DROP TABLE #xyz;
CREATE TABLE #xyz(
[a] [datetime] NULL,
[b] [nvarchar](255) NULL,
[c] [nvarchar](255) NULL
) ON [PRIMARY]
GO
IF (object_id('tempdb..#xyz') IS NOT NULL)
DROP TABLE #xyz;
CREATE TABLE #xyz(
[a] [datetime] NULL,
[b] [nvarchar](255) NULL,
[c] [nvarchar](255) NULL,
[d] [nvarchar](255) NULL
) ON [PRIMARY]
SELECT [d] FROM #xyz
This says:
Msg 207, Level 16, State 1, Line 13
Invalid column name 'd'.
Again, if we try like selecting *
as mentioned by Martin Parkin, it gives result with column name d
.
I could not select *
for my dynamic columns and it doesn't let me to select additional columns.
Why?