Questions tagged [select-into]

The SQL command SELECT INTO statement copies data from one table into a new table. See https://www.w3schools.com/sql/sql_select_into.asp

SELECT INTO is available in various database systems so please tag the type of database being used as well.

158 questions
3
votes
2 answers

How do I add a NULL column when SELECT'ing INTO a new table?

I have a statement like this: SELECT field1, field2, MyField = NULL INTO NewTable FROM OldTable This does what I want with one exception: the field I created MyField and filled with NULL is an INT type and I'd like it to be a VARCHAR type. I…
Baub
  • 723
  • 4
  • 21
  • 36
3
votes
1 answer

oracle - multiple insert into type table collection

I have created the following object in oracle 11g. CREATE OR REPLACE TYPE myObject as object( fieldOne number, fieldTwo number ); And created a new table type of myObject; CREATE OR REPLACE TYPE myTable IS TABLE OF myObject; I would now like to…
Timbob
  • 35
  • 1
  • 4
2
votes
3 answers

"Unexpected ordering of clauses" error when exporting an Excel file in MySQL

I need to export the result of a query to a CSV file in MySQL. I wrote: SELECT orders.user_id, orders.order_id, members.name, members.family, orders.agent_id, CONCAT(m.name, ' ', m.family) AS agent_name FROM orders JOIN members ON…
Ahmad Badpey
  • 6,348
  • 16
  • 93
  • 159
2
votes
0 answers

SSMS: creating a new table from other tables that automatically refreshes

I have created a new table using a SELECT INTO statement. I want the new table to automatically refresh if the original table changes (i.e. new rows of data added). I have googled around but can only find solutions to refreshing a views, not…
Jimbo
  • 67
  • 9
2
votes
1 answer

SELECT * INTO newtable not working

So in Db2/IBM Data Studio I am unable to run this: SELECT * INTO newtable FROM oldtable I am getting this error message: The "newtable" is not valid in the context where it is used..sqlcode=-206 sqlstate=42703, driver=3.68.61. The table…
2
votes
1 answer

Using COUNT(*) and INTO oracle sql

I have select statement like this: with input as (select id,date,quantity from abc a,xyz z .......) select count(*) from input t where .....; this statement gives me a result of 0 and i want to use…
Kate
  • 445
  • 3
  • 9
  • 22
2
votes
2 answers

sql-make a tablename string that includes getdate

I'm tryin to do this: select * into 'DataBackup'+convert(varchar(10),getdate(),112)+'byMike' from SomeTable but it returns an error. I also tried this one but to no avail: select * into (select…
Ugur
  • 312
  • 5
  • 15
2
votes
4 answers

SQL Server: preserve calculated fields with a SELECT INTO

My company performed a data migration recently (in a SQL Server 2005 database) and we noticed that some tables created with SELECT INTO didn't maintained the calculated fields of the original tables, but instead SQL Server created regular fields…
Alberto Martinez
  • 2,620
  • 4
  • 25
  • 28
2
votes
2 answers

Why is Oracle SELECT INTO statement throwing error?

I write a code to create procedure in oracle, It's successful created but when RUN from sql developer to view output it's show error. ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at "TESTUSER.USER_FEEDBACK", line…
Rajiv Choudhary
  • 141
  • 2
  • 14
2
votes
4 answers

UNION ALL on 3 tables with different number of columns in each table - how to do so efficiently

I wanted to use UNION ALL on 3 different tables, merging them into one table by using SELECT INTO. Table 1 ,2 and 3 has 15, 7 and 8 columns respectively. So, was there a way for me to use UNION ALL and have table 2 and 3 default to a NULL for the…
elbarto
  • 211
  • 3
  • 15
2
votes
1 answer

Select * into #table from execute(@query)

I have created a dynamic query which returns the number of columns from table as: set @query = 'select '+@cols+' from [Sample] ' Now I want to fill a temporary table by executing this query, When I try this select * into #table from…
2
votes
1 answer

ERROR: "coalesce" is not a known variable in INTO clause

Following is my sample function create or replace function samp(in a int) returns int as $$ declare val int; val1 int; begin select coalesce(a-1,1) into val,coalesce(a-2,1) into val1; return val + val1; end; $$ language plpgsql when executing it…
bigbiff
  • 75
  • 1
  • 1
  • 8
2
votes
1 answer

MS Access 2010 SQL Select Into Calculated Column Issue

I have a pretty extensive Union query with calculated columns that I'm trying to just "paste values" into a table through a separate SELECT INTO query. I get the error below when executing the query. Is there any way around this without using…
plankton
  • 369
  • 5
  • 21
2
votes
1 answer

Create dynamic table from SQL Query

Using a hybrid Access 2010 / SQL Server 2012 platform - (a solution in either application will work) I have a table created with a Select Into ... statement. Is there any way to have this table dynamically update itself (using the query that created…
mcalex
  • 6,628
  • 5
  • 50
  • 80
2
votes
5 answers

Select Into Explanation / Temporary Tables

Based on the tutorial on SQL Temporary Tables, it should be OK to create a temp table by using SELECT * INTO #tempTable FROM tableA but it's throwing me SQLException when I trying to SELECT * FROM #tempTable saying that Invalid object name…
SuicideSheep
  • 5,260
  • 19
  • 64
  • 117
1 2
3
10 11