9

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

user1557886
  • 237
  • 4
  • 8
  • 14
  • 1
    Refer below link: http://stackoverflow.com/questions/729197/sql-exclude-a-column-using-select-except-columna-from-tablea – bgs Jun 26 '13 at 09:39

1 Answers1

18

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
bgs
  • 3,061
  • 7
  • 40
  • 58
  • If the column is dropped, i cannot join the temp table with main table – user1557886 Jun 26 '13 at 09:44
  • Use another temp table to temporary store table values.. Otherwise you manually need select only required columns in view – bgs Jun 26 '13 at 09:49