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
0 answers

SQL Server Conditional Select Into Issue

I am working on a task where i had to enhance the performance of the stored procedure. However, i had stucked in an issue is that i am unable to use SELECT INTO in a conditional statement. I had gone through some links like INSERT INTO vs SELECT…
0
votes
2 answers

PL/SQL Function, how to use SELECT INTO clause to declare variables from an existing table?

I would like to create a PL/SQL Function that calculates the age of any person from an existing table "Family tree" (Familienbaum), based on their Name. The Table has the needed Values Name, BirthYear (Geburtsjahr), YearOfDeath (Sterbejahr),…
Alexy
  • 23
  • 7
0
votes
2 answers

Macro variable (date) not working as expected in query

I've several SAS (PROC SQL) queries using a MIN(startdate) and MAX(enddate). To avoid having to calculate these every time I want to do this once at the beginning and store it in a macro variable but I get an error every time. What is going wrong or…
John Doe
  • 9,843
  • 13
  • 42
  • 73
0
votes
1 answer

MySQL Aggregate GROUP_CONCAT and JSON_ARRAYAGG functions returning duplicate values inside stored procedure

Aggregate functions are working for my on command line and in my SQL client, but when I run those very same aggregate functions for use in setting a variable inside a stored procedure, I get duplicate values - the same number of values for multiple…
0
votes
2 answers

Oracle Trigger error 'Statement Ignored' and PLS-00405:sub-query not allowed in this context

I am getting the following two errors in the screenshot while trying to create the trigger. Can somebody please tell me what am I doing wrong while passing values in the variables user_audit and user_evdnse using SELECT INTO? create or replace…
Reeya Oberoi
  • 813
  • 5
  • 19
  • 42
0
votes
0 answers

Getting duplicate column ERROR while trying to insert same column with two different datatypes using SELECT INTO clause in PostgreSql

I need to insert createdate column twice with two different datatypes one with the datatype defined in the table itself and another in char datatype. I can insert it by changing the alias name of createdate column but can't insert with same alias…
0
votes
1 answer

MySQL - SELECT INTO (SQL Error (1045): Access denied for user 'test'@'%' (using password: YES))

When I try to export records using the below query, I am getting an error SELECT ID, Name FROM Emp INTO OUTFILE 'C:/temp/hash.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY '\r\n'; Error: SQL Error (1045):…
aka baka
  • 213
  • 2
  • 10
0
votes
1 answer

SELECT ... INTO variables set CONTINUE HANDLER FOR NOT FOUND to 1(TRUE)

SELECT ... INTO variables set CONTINUE HANDLER FOR NOT FOUND to 1(TRUE). This was discovered in 5.6.37 version. As example see next code. DECLARE t_teil_sachnr, t_teil_alt CHAR(7); DECLARE v_optm_id_sachnr, v_optm_id_alt INTEGER DEFAULT…
0
votes
1 answer

Viewing detailed info for Stored Procedure compilation error(PL/SQL: ORA-00933)

This procedure is supposed to copy user info from one table to another. It is executed with spring mybatis, and the spring retrieves some results by procedure's parameters. There is a compilation error at SELECT ... INTO ... statement. PL/SQL: SQL…
coding monster
  • 384
  • 4
  • 18
0
votes
1 answer

How to use autoincrement for a SELECT INTO of a GROUP BY result in MySQL?

I found this SET @row_number = 0; SELECT (@row_number:=@row_number + 1) AS num, firstName, lastName FROM employees ORDER BY firstName, lastName solution here for adding row numbers to a MySQL result, but it doesn't work for a…
csabinho
  • 1,579
  • 1
  • 18
  • 28
0
votes
1 answer

PL/SQL API call/query returns multiple records, how to pass into multiple variables

I have this api_call in oracle sql like this: select sb_transfer_crse.f_query_all('000497') from dual; The response looks like this: SHBTATC_SBGI_CODE SHBTATC_PROGRAM SHBTATC_TLVL_CODE SHBTATC_SUBJ_CODE_TRNS SHBTATC_CRSE_NUMB_TRNS …
moore1emu
  • 476
  • 8
  • 27
0
votes
1 answer

In clause of a select but with more than one value to look for

I have a set of results that I query with connect by prior, now I need to check in the where clause of a query if ONE of those results is IN some other set of values(a select * from another table). I'm trying to use 'IN' but I think that that only…
Golan_trevize
  • 2,353
  • 5
  • 22
  • 22
0
votes
0 answers

Using SELECT INTO for a multi-table query

I've been using a script that a coworker showed me to query against all of our databases. It starts with CREATE TABLE #tempTable and then I need to define all the columns. I was wondering if it was possible to not define the table and use SELECT *…
Jon C
  • 11
  • 1
0
votes
1 answer

Selecting from Same Column into different variables

Values Id's 1 120 1 120 0 120 0 120 0 120 Not applicable 120 Not applicable 120 Empty …
0
votes
2 answers

Alternative for IF statement in plsql select Into

I have a select statement like below using IF condition If (v_block = 'apple') then select count(*) into v_apple_id from table_fruits where fruit_id = v_fruit_id; elsif (v_block = 'mango') then select count(*) into v_mango_id from…