user1557886 user1557886 - 5 months ago 21
SQL Question

How to remove the first column from a temp table select

I have a temparory table.temp table is created using select into statement.

Temp table columns are dynamically created .column numbers may vary.

For eg.
Temparory table
ID,Addrss1,Address2,Address3

ID, Address1,Address2,Address3,Address4,Address5.....


All temp columns have the First column as ID.I need to create a view with base table and
temp table

I need to avoid the first column of the temporary table in the select statement of the view.I cannot take temp.*.it will take ID.I do not want ID in the select statement.

Any help appreciated

bgs bgs
Answer

Just try below script:

/* Get the data into a temp table */
SELECT * INTO #TempTable
FROM YourTable
/* Drop the cloumns that are not needed */
ALTER TABLE #TempTable
DROP COLUMN ColumnToDrop
/* Get results and drop temp table */
SELECT * FROM #TempTable
DROP TABLE #TempTable
Comments