Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 914
user1557886 Avatar asked Jun 26 '13 09:06

user1557886


People also ask

How do I remove a specific column from a table?

Right-click the column you want to delete and choose Delete Column from the shortcut menu. If the column participates in a relationship (FOREIGN KEY or PRIMARY KEY), a message prompts you to confirm the deletion of the selected columns and their relationships. Choose Yes.

How do you clear a temp table?

Using the DROP TABLE command on a temporary table, as with any table, will delete the table and remove all data. In an SQL server, when you create a temporary table, you need to use the # in front of the name of the table when dropping it, as this indicates the temporary table.

How do I remove one value from a column?

Use the DELETE command to replace the value in a column with null or to remove an entire row of data. CQL provides the DELETE command to delete a column or row. Deleted values are removed completely by the first compaction following deletion.


1 Answers

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
like image 112
bgs Avatar answered Oct 24 '22 01:10

bgs