Questions tagged [sql-insert]

1

votes
1

answer
4.6k

Views

Insert into table from another table where the records don't exist

I'm trying to figure out how to insert into an existing table (tbl01) from a temporary table (temp) where the records do not already exist in the existing table (tbl01). I hope that makes sense. I'm basically, trying to update a table with records that have occurred since the last update of the ta...
DJDJ23
1

votes
1

answer
132

Views

MySQL INSERT INTO statement generating “Error Code: 1136. Column count doesn't match value count at row”

I am trying to create a new table from an old table so I can remove some duplicates and implement a composite primary key. I have created the new table from the old one using LIKE, so the columns should be identical. Why does this not work? INSERT INTO PricesNEWtest (Global_MarketCap,pkey) VALUES ((...
Ricky
1

votes
2

answer
34

Views

Extract Year from Date and insert into new field

I know I can extract the Year of my ordered_date field with SELECT YEAR(STR_TO_DATE(ordered_date, '%Y-%m%d')) from wccrm_orders I tried with insert into wccrm_orders (year) values (SELECT YEAR(STR_TO_DATE(ordered_date, '%Y-%m%d')) from wccrm_orders) But it just adds empty entries after the last id.....
Bosstone
1

votes
1

answer
19

Views

How to insert data from multi tables to one table in Oracle?

I'd a trouble with inserting data from 3 table: A (id, name), B (id, name), C (id, name). They have the same field like that. How can I insert data from 3 tables above into table D (id, name)?
leebongee
1

votes
2

answer
2.6k

Views

PostgreSQL: LEFT JOIN creates blank row

See important new discoveries 1 and 2 at end of this explanation. I am running Postgres 9.1.3 and am having a weird left join issue. I have a table named consistent.master with over 2 million rows. It has a column named citation_id, and that column has no nulls. I can verify that with this: SELECT C...
Aren Cambre
1

votes
0

answer
39

Views

Oracle sql: insert into by copying from two different tables

Although it's much more complex than I'm about to explain, I'll try to only stick to the relevant bits of what I want to accomplish. Our data model is quite complex, and the terms are also a bit confusing. We basically have a Request, and this request can have an active Request_Status (which has an...
Kevin Cruijssen
1

votes
2

answer
176

Views

INSERT TIMESTAMP or DATETIME fails when month, day, hour or min is 8 or 9

I'm having a strange problem while dealing with inserting datetime values. it happens while inserting DATETIME or TIMESTAMP type columns, as well as when using STR_TO_DATE function. it seems that the database cannot parse correctly when the month, the day, the hour or the minute are number 8 or 9. S...
agregorio
1

votes
2

answer
201

Views

SQL avoid inserting duplicate new shopping cart id

(First and foremost, sorry for my bad English, it is not my first language.) I have a SQL database table to store some shopping cart, that likes something like this: Shopcart ---------- ID(PK) shopcartid price user 1 S123 112.00 Tom 2 S124 6543.00 Mary 3...
LCCDerek
1

votes
1

answer
37

Views

Conditional insert sql server for more than one row

I am trying to insert a value for every Call Record with a specific date, note and action when a client matches listed emails. The problem is that there are many other call records for these clients, so if I use a select query in the Insert statement, it will add many more rows that I want - I just...
Robert Woolfson
1

votes
0

answer
54

Views

tJdbcOutput component Delay for Table insert in Talend 6.4

I am using a one to one mapping for loading data into a MSsql server table. This mapping is simple and contains only two components. tFileinputDelimited for reading and tJdBCoutput for inserting into table. we are using a tJdbcoutput component to load data into table. We have created the mapping in...
TomG
1

votes
3

answer
113

Views

Logical lock in WHERE clause

Since FUNCCODE is shared between POSCODE and DEVCODE I can't call out both at the same time to eliminate the null values to insert the data into a separate table called JOINT. POSCODE and DEVCODE are FKs. I know there has to be a much easier way of doing this. I spent the last 2 weeks trying to cra...
Brandoncbaldwin
1

votes
2

answer
35

Views

PHP script doesen't insert data in MySQL

I've created this script to insert some data from PHP to MySQL, but it doesen't work, and I don't know why. if (isset($_SESSION['userSession'])!='') { $session_created=1; $session_query = 'SELECT * FROM users WHERE user_id='.$_SESSION['userSession']; $session_query_result = $DBcon->query($session_qu...
1

votes
1

answer
21

Views

Mysql select statement contains where clause so unsuitable for insert into

I'm very inexperienced. I've prepared a select statement which gives the information I need to populate a matches table. However it is not suitable because it contains a where clause. Is there a different way to use it, or how can I change it so that it is suitable for INSERT INTO. The tables are as...
Liz
1

votes
1

answer
41

Views

Store Procedure hit SQL Statement Ignored

create or replace PROCEDURE GEN_STATEMENT_SP(indexNM IN VARCHAR2, tableNM IN VARCHAR2) AS BEGIN DECLARE uniqueSTMT VARCHAR2(30); nonUniqueSTMT VARCHAR2(30); charOn VARCHAR2(5); tempfld VARCHAR2(500) ; CURSOR chkTyp IS(SELECT ES_UNIQUENESS from sys.dba_ind_columns where INDEX_NAME = indexNM and TAB...
GTeckHan Goh
1

votes
0

answer
36

Views

How can I execute multiple prepared SQL statements from a single input button press in php?

Context: The page is for menu item entry into an order. When a menu item button is pressed, data from 'theProducts' table is queried and inserted into 'theOrderItems' table. I also want the same button press to take the serving size value (theProducts.dbProdServing) and subtract that amount from the...
Jack Phillips
1

votes
1

answer
40

Views

How to get column data combining old.variablename in Postgresql?

I'm trying to build an audit trigger function (that works for more than one table) that retrieves the column of the table's primary key. For example, there's a table customers that has 'customerid' as primary key, and there's a table orders that has 'orderid' as primary key. With this, i find the n...
ShootingWizard
1

votes
1

answer
20

Views

Get Average and upload into new db table mysql

I am trying to get the average of the columns in my table and then insert the averages into a second table, I have over 30 columns so I would rather not have to do them all individually if possible command.CommandText = ' INSERT INTO FaceAverages(`rightEyeRightUpper`),(`rightEyeLeftUpper`),(`righ...
the pro-gramer
1

votes
0

answer
74

Views

Best way to handle Insert/Update statements in SQL Server 2008?

I have been working on design of new system and there is many situation where function will handle Insert/Update statements. Usually this kind of process is handled old fashion way using server side language to determine which query will be executed. There is few things that I would like to eliminat...
espresso_coffee
1

votes
0

answer
36

Views

PHP pdo trying to insert to mysql without success

I am working on my script 1 month now I tried to insert data to mysql but i got an error Error Fatal error: Call to a member function prepare() on string $post_id = $_GET['post_id']; // VALUE : '23' $season = $_GET['season']; // Value : '2' $statement = $link->prepare('INSERT INTO seasons (post_id,...
kaki
1

votes
1

answer
60

Views

Multiple MySQL insert from PHP data get dynamically from ajax

I'm trying to insert multiples values that I get from ajax form. Something like this: Array ( [0] => Hashtag1 [1] => Hashtag2 [2] => Hashtag3 [3] => Hashtag4 ) Then I get an photo in the request and id from the user owner of this photo. I have 3 tables that will receive inserts, and a lot of them. B...
Raikish
1

votes
0

answer
33

Views

Update on duplicate key making a new row (MYSQL-PHP)

I am trying to do a simple SQL statement as follows: INSERT INTO imeiTable (imei, id) VALUES ('imei','ID') ON DUPLICATE KEY UPDATE id='ID' Which works perfectly as intended (Where IMEI is the primary key, and IMEI and ID are numbers). However, when I try to do this statement via PHP, I get a strange...
Lain
1

votes
1

answer
30

Views

Inserting CSV with blank value into SQL table with BIGINT column

I am attempting to insert a number of CSV files into a SQL Server (2016) table. One of the CSV files contains a blank value, for example: ID, VALUE, DATE 235425, 34, '2018-05-08' 234567, , '2018-05-08' 233456, 67, '2018-05-08' The process I am running attempts to insert this value into a BIGINT col...
RDG
1

votes
0

answer
21

Views

ssis sql task editor to create sheet and range

I have an SSIS package that contains a SQL task to create aN excel table once its been dropped, this works fine, my question is is it possible to either have a sql task to create a worksheet and a range. or a SQL task to insert data into a particular range within a previously created worksheet?
sql2015
1

votes
1

answer
26

Views

How to fix 'TypeError: expecting string or bytes object' error in Python

I want to insert a row into table. But i got TypeError: expecting string or bytes object this error. Traceback (most recent call last): File 'd:\Git\Repos\mavi\oracle_connection.py', line 19, in c.prepare(QUERY,{'expr':expr, 'expr2':expr2}) TypeError: expecting string or bytes object import cx_Or...
Şevval Kahraman
1

votes
0

answer
22

Views

Calculate the mysql field during insertion automatically

I have given the image: Here is one to many relationship in b/w the Place and image. Now Total_Images field inside the Place table is dependent on the Image table. Now i want when the user insert the new image inside the Image table then the Total_Images field inside the Place should be auto calcula...
Ishmal Ijaz
1

votes
1

answer
253

Views

Rows disappears from SQL Server Table after Insert and Commit

I have a SQL Server table with only one column and below is the query I use to insert data. I always 'COMMIT TRAN' after the row has been inserted, but the newly added row disappears a few days after I inserted/commit tran. I have never had this issue with any other table and I use these transaction...
user6343282
1

votes
2

answer
27

Views

Continuing Execution after Exception found

I am making a small program to insert from a text document into a database. I used a hashmap to get the values from the text document because I do not want to use arrays and the text document is in format Key:value. At the moment my code inserts correctly but when an exception is found the program e...
Curious George
1

votes
1

answer
422

Views

Dapper Execute function that can call PostgreSQL function and return rows affected from update or insert

I am trying to create a postgresql function that does an update. I want to get the rows affected. I know this can be done by using GET DIAGNOSTICS rows_affected = ROW_COUNT. But I am trying to use the Dapper Execute function which can return rows affected on its own. As far as I've been able to dete...
Joe M
1

votes
0

answer
35

Views

Insert into table by filtering date from another table?

As a overview we are trying to analyse one kind of eCommerce delivery business, where our today's business depends on last evening and today's morning orders And our business team defined the below for any given day's business Evening order: Period (previous day(Today -1) 18:00:00) to Today 01:00:00...
rajkumar21
1

votes
0

answer
24

Views

“attribute 5 has wrong type” when inserting jsonb with ON CONFLICT into a postgres view?

I have a roles table that looks like this: Table 'public.roles' Column | Type | Modifiers -----------------+---------+---------------------------------------------------- id | integer | not null default nextval('roles_id_seq'::regclass) name | text...
Noah
1

votes
1

answer
46

Views

I'm getting a 'column not allowed' error [duplicate]

This question already has an answer here: Oracle SQL: Column not allowed 3 answers I fired following query (exactly same). But Oracle is responding with an error column not allowed ' insert into student (rollno,name,address) values (1,'kartish khanolkar' 'kudal') Table is as follows: create table...
1

votes
3

answer
73

Views

SQL syntax error when inserting data into multiple tables

I am trying to insert data into multiple tables using two insert queries between a BEGIN; and COMMIT; but I am getting a syntax error as below: You have an error in your SQL syntax; it seems the error is around: 'INSERT INTO company ( name, street, zip, place, phone, ' at line 2 This is my query: BE...
twan
1

votes
0

answer
52

Views

Python script inserting into MySQL Table

I've been working on a python script that pulls and organizes data from a website, and then attempts to reproduce that data in a MySQL table. For the purposes of this question, this table's name is 'capacitors', but I intend to eventually have more tables for more categories. The one thing I can'...
Jonny1998
1

votes
1

answer
59

Views

Compute field - insert into m2m relation table

In model project.task I create many2many field x_something linked to another model. So, in this relation table there is a field id from project.task and another model. And in another field of project.task I wanna write a function in compute section and in this function I wanna insert a record into...
LukaszK
1

votes
0

answer
26

Views

MySQL copy selected fields from one row in table 1 to table 2 with different columns and then delete the entry from table 1?

I have table named 'Fruit' with 5 columns ('fruit_id', 'name', 'color', 'size', 'weight') where 'fruit_id' is AUTOINCREMENTED. In this table I have 3 entries: 1, Apple, Red, Medium, 1.0 2, Banana, Yellow, Small, 0.5 3, Pear, Green, Large, 2.0 Of which, I only want to copy the following selected fie...
Jae Bin
1

votes
1

answer
66

Views

ORA-02291: parent key not found when inserting multiple rows

I having a problem executing an stored procedure that does multiple inserts I am a copying 30 tables from a instance of a server to another by a DBLINK: INSERT INTO [email protected] (column1) SELECT column1 FROM table; But it results in: ORA-02291: integrity constraint (string.string) violated - par...
Jpdg
1

votes
0

answer
9

Views

Oracle 10g: insert multiples values from inner select, along with constants

I'm having a query returning multiple rows. These row are inserted into a table as follow: insert into some_table (dte, issues) select dte, issues from ( .. ) di group by dte; During the insert, I would like to the following values: i_ref coming from the function parameter Any others value (eg v_tot...
Hey StackExchange
1

votes
2

answer
112

Views

SQL Server : update trigger seeming to affect wrong column

Thanks for looking. I'm trying to write a SQL Server trigger that when a new record is added containing date information, will add the day of the week to the DayOfWeek column. Here's my table, with the columns in order: Food table: FoodName **varchar(20)** CategoryID (FK) **int** Price **smallmo...
Jack Harris
1

votes
3

answer
125

Views

Cannot insert data, foreign key error on postgresql

I have 3 tables, where the table INTRUSIONS have foreign keys belonging to CCTVS and ALARMS tables. I want the foreign keys to be nullable in my INTRUSIONS table. I am not sure why but I cannot insert data into my 'INTRUSIONS' table. Here is my code: CREATE TABLE REMOTE_SECURITY.CCTVS(CCTV_ID ser...
Amoroso
1

votes
0

answer
48

Views

Insert multiple rows - SQL Error: near “,”: syntax error

In my SQLite I want to insert 2 rows. INSERT INTO notification_invoice (amount,currencyISOCode) VALUES (1.1,'498'), (34.2,'980'); But I get error: 30-Nov-18 12:21:21: SQL Error: near ',': syntax error INSERT INTO notification_invoice (amount,currencyISOCode) VALUES (1.1,'498'), (34.2,'980'); >
Alexei

View additional questions