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
0
votes
1 answer

What locks are involved with Select INTO statement?

In MySQL, just like there is locking involved with SELECT combined with INSERT or CREATE, does the same hold true for SELECT column INTO @variable statement?
Deb
  • 337
  • 3
  • 14
0
votes
1 answer

Run a Select-into command to create a new table for each UNIQUE value of a particular column

I have a table on SQL Server database from which I need to create different tables for each unique value of a particular column. I tried below code: DECLARE @i int DECLARE @numrows int DECLARE @indexcount int DECLARE @Group varchar DECLARE…
0
votes
1 answer

Select into statement for null or more than one value

I am stuck in plsql , as I have making function in which I have to update a table if only values comes in select into .. and if not come then not and if multiple comes then have to update and delete for all that values . In below function if in…
0
votes
1 answer

SQL Statement Insert Into

I'm getting the following no matter what I do any help would be awesome. Msg 116, Level 16, State 1, Line 15 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. Msg 109, Level 15, State 1, Line…
larry
  • 41
  • 10
0
votes
2 answers

sql stored procedure, select into

i try to build a store procedure who insert data to a table, after it run, the table is empty. this is the code: CREATE TABLE invoices (invoiceNo int, invoiceDate date, invoiceTotal int, invoiceType char(1)) alter PROCEDURE Invoices_AGG @year…
JOE
  • 1
  • 1
0
votes
1 answer

MySQL/MariaDB setting values with INTO inside cursor has incorrect iterations

Could someone please explain me why if I run this code: BEGIN -- Declare loop constructs -- DECLARE done INT DEFAULT FALSE; -- Declare Person variables -- DECLARE s_trnsf_id INT(11) DEFAULT NULL; DECLARE…
sag
  • 177
  • 1
  • 6
0
votes
1 answer

Dynamic SQL SELECT INTO returns dreaded ORA-00933: SQL command not properly ended

I am executing the following dynamic statement and receiving the ORA-00933: SQL command not properly ended: FUNCTION IsValidArchive RETURN BOOLEAN IS x BOOLEAN := TRUE; isValidArc_sql VARCHAR2(2000); BEGIN isValidArc_sql :=…
0
votes
2 answers

Select values from different rows of same column INTO multiple variables in Oracle SQL

Here's the example: ID | value 1 51 2 25 3 11 4 27 5 21 I need to get first three parameters and place them into variables e.g. out_x, out_y, out_z. Is it possible to do it without multiple selects?
MickeyKSP
  • 43
  • 1
  • 10
0
votes
1 answer

How do I add the result of a SELECT as a new column in an existing table?

In SQL (whichever variant you like, say MySQL or MonetDB) it's very intuitive and straightforward to do: CREATE TABLE t2 AS SELECT c1 FROM t1; and get the selection result as a new column in a new table. But what if you want the result as a new…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
3 answers

Fetch multiple values in a single variable and use that to compare with a single value in another variable

I have a requirement to fetch multiple values through a select query and into a single variable and then compare the value of that variable with another variable having only single value. I am new to PL/SQL programming. I have searched this forum…
suk15
  • 49
  • 7
0
votes
1 answer

Why is the size of duplicated table so much smaller than original?

I have a table [ExampleSource] where SQL Server Management Studio indicates the following storage statistics: Index space: 58 MB Row count: 28269319 Data space: 4,567 MB I copied the table using the following command with the intention of…
c31983
  • 449
  • 4
  • 16
0
votes
1 answer

Error message while using Select Into

I used below code, SELECT RowsCount = ROW_NUMBER() OVER(ORDER BY PrijsBoek.[Item Code] DESC, PrijsBoek.[Buy-From BP Code] DESC), * INTO #Student FROM [iqbs DataWarehouse].[Purchase].[factPurchasePriceBooks] as PrijsBoek DECLARE @MaxRowsCount…
0
votes
1 answer

Oracle PL/SQL Select into variable using WITH clause

I have a WITH clause that gives me the desired result, and i'm trying to put it in a variable. I have omitted code for simplicity. The last line of code is most relevant. WITH ALL_VE_ERRORS AS ( SELECT * FROM…
SomeRandomDeveloper
  • 489
  • 2
  • 13
  • 33
0
votes
2 answers

T-SQL: SELECT INTO sparse table?

I am migrating a large quantity of mostly empty tables into SQL Server 2008. The tables are vertical partitions of one big logical table. Problem is this logical table has more than 1024 columns. Given that most of the fields are null, I plan to use…
tomfanning
  • 9,552
  • 4
  • 50
  • 78
0
votes
2 answers

MySQL select statement in stored proc returns different results than outside of proc

I cannot figure out why the exact same query that runs outside of a mysql proc does not return the same data inside of it. Here is the proc. DELIMITER $$ USE `poll_app`$$ DROP PROCEDURE IF EXISTS `record_new_vote`$$ CREATE…
user2278120
  • 623
  • 2
  • 9
  • 22