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
1
vote
1 answer

Value of variable in Oracle with Select Into not resolving during procedure

I have a timestamp column in one of my tables. I want to get all entries that are a minute after the very first entry in the table. The timestamp is chronological with respect to the primary id. To this end I retrieve the first entry in the table…
Mars
  • 4,677
  • 8
  • 43
  • 65
1
vote
2 answers

checking existence of a row before doing a SELECT INTO (SQL Server)

I have a SQL statement I'd like to amend. As it stands now I'm running a simple SELECT INTO but I'd like to modify it so only records that don't exist in the destination table (as determined by my criteria) are appended. Here's my initial…
larryq
  • 15,713
  • 38
  • 121
  • 190
1
vote
2 answers

Create table under a specific FileGroup WHERE 1=2

I have an WinForms application which creates tables dynamically based on a given table such as: SELECT * INTO TempTable FROM MyTable WHERE 1=2 I want those Temp tables to be created under a specific filegroup though using the above syntax. The…
alwaysVBNET
  • 3,150
  • 8
  • 32
  • 65
1
vote
2 answers

Copying a SQL Server table and adding and rearranging columns

I know that if I want to make a copy of a SQL Server table, I can write a query akin to this: SELECT * INTO NewTable FROM OldTable But what if I wanted to take the contents of OldTable that may look like this: | Column1 | Column2 | Column3…
JohnN
  • 968
  • 4
  • 13
  • 35
1
vote
1 answer

Concatenate string variables into a new variable in new table

I am trying to concatenate 5 string variables into a new string in a new table. SELECT [id],IsNull(Cast(x01 as nvarchar(4000)),'') + IsNull(Cast(x02 as nvarchar(4000)),'') + IsNull(Cast(x03 as nvarchar(4000)),'') + IsNull(Cast(x04 as…
user2964644
  • 189
  • 9
1
vote
2 answers

Creating a table in SQL Server using SELECT ... INTO

i am creating a table in sqlserver database using query like "SELECT Table1.* INTO Table2 FROM Table1" here Table2 created successfully but it is not showing my database when i again fire this query than it gives error that Table2 is already created…
harsh
  • 17
  • 1
  • 5
1
vote
1 answer

Sql multiple select into

How can I set multiple into inside a select query in Oracle according to the following sql query. declare v_a out varchar2; v_b out varchar2; v_c out varchar2; begin select a , b , c into v_a, v_b, v_c from table end
Goran Zooferic
  • 371
  • 8
  • 23
1
vote
2 answers

combining a sort, select into, and where statement to find a max value in oracle sql

I am trying to do a select into statement to get a max value from a column. This is what I have: SELECT stdid INTO v_stdid FROM (SELECT stdid FROM STUDENT ORDER BY stdid DESC) WHERE ROWNUM = 1; I don't get the correct value though. It…
teppuus
  • 89
  • 2
  • 2
  • 8
1
vote
1 answer

MS SQL SELECT INTO table auto generate unique identifier for every row

I try to create new table in MS SQL server 2008 using SELECT INTO statement. I want every row of the new table has auto-generated ID of UNIQUEIDENTIFIER type as a first column. Code sample without ID column: SELECT m.sellThru, m.turnover INTO…
mzy
  • 1,754
  • 2
  • 20
  • 36
1
vote
2 answers

Insert into combined with select where

Let's say we have a query like this (my actual query is similar to this but pretty long) insert into t1(id1,c1,c2) select id1,c1,c2 from t2 where not exists(select * from t1 where t1.id1=t2.id1-1) Does this query select first and insert all, or…
Uğur Gümüşhan
  • 2,455
  • 4
  • 34
  • 62
1
vote
2 answers

How to INSERT INTO...SELECT with ON DUPLICATE KEY

I have two tables with identical structure. Table A contains all the current ads, Table B contains the archived ads. Column 1 (ad_id) is Primary Key, AI, INT. Table engine is MyISAM. I need to copy all the table A ads preceding a certain date to the…
Gary D
  • 153
  • 1
  • 10
1
vote
1 answer

MySQL into outfile formatting

select * INTO OUTFILE 'outfile.txt' FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' from nGrams Is there any way I can modify this query to return each row on one line?
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
1
vote
3 answers

How to Move Rows from Table A to B and Select Only the Moved Rows from A?

I need to move all existing rows in table A over to table B. I also need to select ONLY the moved rows from table A. (Not from Table B since Table B is an archive and contains a lot of rows which will result in the select taking a lot of time) I'm…
Harindaka
  • 4,658
  • 8
  • 43
  • 62
0
votes
0 answers

Proc SQL Select Into not working as I would like

One (I hope simple) question: why does the following code DATA DIZIONARIO; INFILE DATALINES DELIMITER=" "; INPUT ENTRY $ TRADUZIONE $; DATALINES; 0 K 1 5 2 L 3 9 4 G 5 3 6 Y 7 0 8 U 9 X ; RUN; %MACRO CODIFICA (VARIABILE); PROC…
0
votes
0 answers

Select insert into composite primary key tables

I have a table with a composite primary key of 3 values: SELECT sifra_kapit_proj, sifra_aktivnosti, sifra_funkcije, naziv_aktivnosti, row_version, sifra_programa FROM EFIN00123..aktivnost The 3 starting with…