update with concat in where clause mysql - mysql

I have this schema:
CREATE TABLE `devolucion_medicamento` (
`id_devolucion_medicamento` int(11) NOT NULL,
`id_devolucion` int(11) NOT NULL,
`id_medicamento` int(11) NOT NULL,
`cantidad` int(11) DEFAULT NULL,
`fec_mov` timestamp NULL DEFAULT NULL,
`activo` tinyint(1) DEFAULT NULL,
`lote` varchar(45) DEFAULT NULL,
`fec_venc` date DEFAULT NULL,
`tamano` varchar(45) NOT NULL,
`inventario` varchar(45) NOT NULL
)
and i have to update the value of "inventario" where id_medicamento,fec_venc,tamano and inventario are equals to some concatenated string value that i get from an app.
I thought on something like this
UPDATE devolucion_medicamento
SET
inventario="AAAAAA",
WHERE concat(id_medicamento,lote,fec_venc,tamano,inventario)="54062018-09-308"
but i don't know if it is possible in mysql.
I'm having this error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE concat(id_medicamento,lote,fec_venc,tamano,inventario)="54062018-09-308"' at line 4

I'm too new to comment... but it appears there is a comma after inventario="AAAAAA". If so, MySQL is expecting another set expression.

Related

How do I debug SQL query with the following error message

This is my query.
CREATE TABLE `requirements`
(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`requirement_id` VARCHAR NOT NULL,
`state` VARCHAR NOT NULL,
`city` VARCHAR NOT NULL,
`salary_per_anum` FLOAT NOT NULL,
`is_closed` TINYINT(1) NOT NULL,
`created_updated` DATETIME NOT NULL,
CONSTRAINT `pk_requirements` PRIMARY KEY(`id`)
);
and this is the error message
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, `state` VARCHAR NOT NULL, `city` VARCHAR NOT NULL, `salary_per_anum` F' at line 1
how can I debug what seems to be the issue?
You need to define a length of the string colum like
`requirement_id` VARCHAR(100)
and the same with column state and city.
But since requirement_id looks like a number id column it must be of the same type as id in table requirements, probably int.
Also your constraint seems to be defined wrong. It should refer to the table requirements.

Enum values and Error 1064

I have a problem with this error.
here is the code to create the table
CREATE TABLE `qa`.`question`(
`id` INT(9) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`password` VARCHAR(256) CHARACTER SET utf16 COLLATE utf16_general_ci NOT NULL,
`email` VARCHAR(512) NOT NULL,
`phone` INT(11) NOT NULL,
`content` TEXT NOT NULL,
`status` ENUM(0) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB CHARSET = utf8 COLLATE utf8_general_ci;
I see the same question , but none of them occur in my code .
I think about default value too , but I receive this:
Invalid value for id (error #1067)
I can't reproduce the error you got. I got a different error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0) NOT NULL,
This is because the elements of an ENUM must be strings, not numbers. I changed it to:
`status` ENUM('OK', 'FAIL') NOT NULL,
and the table creation succeeded.
The error you got would happen if you tried to assign a default value to the id column, because it's also declared to use AUTO_INCREMENT. See #1067 - Invalid default value for 'bonusid' how can i fix this error?

What is wrong with my code for phpmyadmin?

I tried to make a database is phpmyadmin, but I keep getting an error.
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0) NULL,
Datum Verkocht DATE NULL,
Personeel VARCHAR(30) NULL,
`Min' at line 9
That's for this code
CREATE TABLE `veilingen`.`Veilingen`(
`Nr` INT(3) NOT NULL,
`Artikel` VARCHAR(100) NULL,
`Datum Geveild` DATE NULL,
`Tel. Verkoper` INT(10) NULL,
`Datum Ingeleverd` DATE NULL,
`Kast`
SET
(0) NULL,
`Datum Verkocht` DATE NULL,
`Personeel` VARCHAR(30) NULL,
`Minimum` DECIMAL NULL,
`Koop Nu` DECIMAL(100) NULL,
`Geveild Voor` DECIMAL(100) NULL,
`Betaald` ENUM(0) NULL,
`Cadeaubon` DECIMAL(100) NULL,
`Versturen` VARCHAR(100) NULL,
`Opmerkingen` VARCHAR(100) NULL,
PRIMARY KEY(`Nr`(1))
) ENGINE = MyISAM;
Sorry for the mess, I can't get the code span to work.
Can somebody help me?
Following is the right syntax for create table in php, you can edit this code according to your table name,column name and it's datatype.
CREATE TABLE employee (
empId int(11) NOT NULL AUTO_INCREMENT,
empName varchar(255) NOT NULL,
empDept varchar(255) NOT NULL,
PRIMARY KEY (empId)
)

SQL Syntax Error When Importing .sql file from mysql 4.0

I am trying to import a .sql file that was created with mysql 4.0 into the latest version of mysql and have received a syntax error regarding the following code:
CREATE TABLE edgemap (
senderid int(10) unsigned default NULL,
recipientid int(10) unsigned default NULL,
messageid int(10) unsigned default NULL,
messagedt timestamp(14) NOT NULL,
reciptype enum('bcc','cc','to') default NULL,
subject varchar(255) default NULL,
KEY senderid (senderid,recipientid),
KEY messageid (messageid),
KEY messagedt (messagedt),
KEY senderid_2 (senderid),
KEY recipientid (recipientid)
) ENGINE=MyISAM;
The error message I receive is:
ERROR 1064 (42000) at line 255752: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(14) NOT NULL,
reciptype enum('bcc','cc','to') default NULL,
subject varchar' at line 5
Any help would be much appreciated!
timestamp has maximum precision of 6 (microseconds):
http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
So change it to
messagedt timestamp NOT NULL,
or
messagedt timestamp(6) NOT NULL,
http://sqlfiddle.com/#!9/221c13
enum may not default to allowing NULL values in mysql 5, try changing that line to:
reciptype enum('bcc','cc','to') NULL,

Throwing MySQLSyntaxErrorException regarding syntax of SQL in Struts

I am making a project on Struts framework.
I am getting a exception from server while inserting data in a table using SQL and I am unable to find the solution.
The error is as following:
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the
right syntax to use near ',,,,,,,'yes','yes',,,,'admin')' at line 1
My code which is generating the error is as following:
sql="Insert into field_visit_details (visit_date,block,village,flw_category,
flw_name,flw_contact_no,aware_zinc,
aware_ors,past_zinc,past_ors,qty_avail_zinc_ten,qty_avail_zinc_twe,qty_avail_zinc_syr,
qty_avail_ors,qty_disp_zinc_ten,qty_disp_zinc_twe,qty_disp_zinc_syr,qty_disp_ors,
stockout_zinc,stockout_ors,diar_cases_seen,diar_cases_reff,diar_deaths_less_than_five,
added_by)
values
('"+field_visit_date+"','"+block_row_one+"','"+village_row_one+"','"+flw_category_row_one
+"','"+flw_name_row_one+"','"+flw_contact_no_row_one+"','"+aware_zinc_row_one+"','"+
aware_ors_row_one+"','"+past_zinc_row_one+"','"+past_ors_row_one+"','"+
qty_avail_zinc_ten_row_one+"','"+qty_avail_zinc_twe_row_one+"','"+
qty_avail_zinc_syr_row_one+"','"+qty_avail_ors_row_one+"','"+qty_disp_zinc_ten_row_one
+"','"+qty_disp_zinc_twe_row_one+"','"+qty_disp_zinc_syr_row_one+"','"+
qty_disp_ors_row_one+"','"+stockout_zinc_row_one+"','"+stockout_ors_row_one+
"','"+diar_cases_seen_row_one+"','"+diar_cases_reff_row_one+"','"+diar_deaths_row_one
+"','"+loginid+"')";
System.out.println(sql);
int x=stmt.executeUpdate(sql);
if(x>0)
SUCCESS="admin";
Table Structure is as following:
CREATE TABLE IF NOT EXISTS `field_visit_details` (
`field_visit_id` int(11) NOT NULL auto_increment,
`visit_date` date NOT NULL,
`block` varchar(100) NOT NULL,
`village` varchar(100) NOT NULL,
`flw_category` varchar(45) NOT NULL,
`flw_name` varchar(100) NOT NULL,
`flw_contact_no` varchar(13) NOT NULL,
`aware_zinc` varchar(10) NOT NULL,
`aware_ors` varchar(10) NOT NULL,
`past_zinc` varchar(10) NOT NULL,
`past_ors` varchar(10) NOT NULL,
`qty_avail_zinc_ten` int(11) NOT NULL,
`qty_avail_zinc_twe` int(11) NOT NULL,
`qty_avail_zinc_syr` int(11) NOT NULL,
`qty_avail_ors` int(11) NOT NULL,
`qty_disp_zinc_ten` int(11) NOT NULL,
`qty_disp_zinc_twe` int(11) NOT NULL,
`qty_disp_zinc_syr` int(11) NOT NULL,
`qty_disp_ors` int(11) NOT NULL,
`stockout_zinc` varchar(11) NOT NULL,
`stockout_ors` varchar(11) NOT NULL,
`diar_cases_seen` int(11) NOT NULL,
`diar_cases_reff` int(11) NOT NULL,
`diar_deaths_less_than_five` int(11) NOT NULL,
`added_by` varchar(100) NOT NULL,
PRIMARY KEY (`field_visit_id`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The query when I printed in the console was :
Insert into field_visit_details (visit_date,block,village,flw_category,flw_name,
flw_contact_no,aware_zinc,aware_ors,past_zinc,past_ors,qty_avail_zinc_ten,
qty_avail_zinc_twe,qty_avail_zinc_syr,qty_avail_ors,
qty_disp_zinc_ten,qty_disp_zinc_twe,qty_disp_zinc_syr,qty_disp_ors,stockout_zinc,
stockout_ors,diar_cases_seen,diar_cases_reff,diar_deaths_less_than_five,added_by)
values
('2014-07-02','ASDASD','','asha','asd+','99','yes','yes','yes','yes',
'12','12','12','12','12','12','12','12','yes','yes','12','12','12','admin')
But the thing is that the query is inserting the data successfully in the table but still server is showing the above error.
I even used the above printed query directly in phpmyadmin and worked well without any problem.
You have a syntax exception in the SQL statement. The error message you have posted point to it.
So, you need to change SQL statement and fix syntax errors. For this purpose you should rewrite it to use PraparedStatement like in the example JDBC PreparedStatement example – Insert a record.
And use appropriate to the database column types set methods when setting parameters to the prepared statement.