Solved

mysql sql statement

Posted on 2011-03-06
9
258 Views
Last Modified: 2012-05-11
UPDATE product SET product.ProductQuantity = (product.ProductQuantity - claimdetail.quantity) WHERE product.ProductId = claimdetail.quantity

the code is work but plese see picture 4712893150132 it deduct only first row
delclaim.png
0
Comment
Question by:teera
  • 3
  • 3
  • 3
9 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 250 total points
ID: 35053407
I think this is wrong
.... WHERE product.ProductId = claimdetail.quantity

It should be
WHERE product.ProductId = claimdetail.ProductID
right ?
0
 
LVL 16

Assisted Solution

by:santoshmotwani
santoshmotwani earned 250 total points
ID: 35053411
can you please give your table structure for
product & claimdetail


0
 

Author Comment

by:teera
ID: 35053424
hi experts
product.ProductId = claimdetail.quantity

this is correct
CREATE TABLE IF NOT EXISTS `claimdetail` (
  `claimid` int(11) NOT NULL AUTO_INCREMENT,
  `claimrefid` int(11) NOT NULL,
  `productcode` varchar(200) COLLATE utf8_bin DEFAULT NULL,
  `productnameshow` varchar(200) COLLATE utf8_bin DEFAULT NULL,
  `productname` varchar(200) COLLATE utf8_bin DEFAULT NULL,
  `quantity` int(11) NOT NULL,
  `mark` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `remark` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `price` decimal(10,2) DEFAULT NULL,
  `chargeprice` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`claimid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=15 ;



CREATE TABLE IF NOT EXISTS `product` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ProductId` varchar(80) NOT NULL,
  `ProductName` varchar(255) DEFAULT NULL,
  `ProductType` varchar(255) DEFAULT NULL,
  `ProductPrice` decimal(15,2) NOT NULL,
  `ProductQuantity` int(14) unsigned NOT NULL,
  `LoShef1` decimal(10,0) NOT NULL,
  `Lostae1` decimal(10,0) NOT NULL,
  `qty1` int(11) unsigned NOT NULL,
  `qty2` int(11) unsigned NOT NULL,
  `LoShef2` int(10) DEFAULT NULL,
  `Lostae2` int(10) DEFAULT NULL,
  `mfbarcode` enum('y','n') NOT NULL DEFAULT 'y',
  `oldbar` varchar(80) DEFAULT NULL,
  `berakable` enum('y','n') NOT NULL DEFAULT 'n',
  `childcode` varchar(50) DEFAULT NULL,
  `breakableamount` int(9) DEFAULT NULL,
  `BarCodeOn` enum('y','n') NOT NULL,
  `useradd` varchar(30) NOT NULL,
  `DateTime` datetime DEFAULT NULL,
  `TimeStamp` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `productService` enum('y','n') DEFAULT 'n',
  PRIMARY KEY (`id`),
  UNIQUE KEY `ProductId` (`ProductId`),
  UNIQUE KEY `ProductId_3` (`ProductId`),
  KEY `ProductId_2` (`ProductId`),
  KEY `ProductName` (`ProductName`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=932 ;

Open in new window

0
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 35053446
try this
UPDATE product SET product.ProductQuantity = (product.ProductQuantity - claimdetail.quantity) WHERE cast ( product.ProductId as int)  = claimdetail.quantity
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:teera
ID: 35053473
hi antoshmotw…
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 'int) = claimdetail.quantity' at line 1
0
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 35053484
UPDATE product SET product.ProductQuantity = (product.ProductQuantity - claimdetail.quantity) WHERE cast ( product.ProductId as int(80) )  = claimdetail.quantity

try this plz
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35053491
I still suspect something wrong in there WHERE condition.
UPDATE product SET product.ProductQuantity = (product.ProductQuantity - claimdetail.quantity) WHERE product.ProductId = claimdetail.quantity

Make sure you are storing 'ProductID' in 'Quantity' column of 'claimdetail' table !!!
How it could be linked ?

See claimtable have some other columns that stands for which project the quantity belongs to

Sorry if I am not clear

Again - Are you storing 'ProjectID' in Quantity column of claimdetails table ?

Raj
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35053594
Spelling mistake - I mean
Again - Are you storing 'ProductID' in Quantity column of claimdetails table ?
product.ProductId  = claimdetail.quantity 

Open in new window

?


0
 

Author Comment

by:teera
ID: 35065822
UPDATE product
JOIN
(
SELECT productcode, SUM(quantity) SUMClaim
FROM claimdetail
GROUP BY productcode
) claims on claims.productcode = product.ProductId
SET product.ProductQuantity = product.ProductQuantity - claims.SUMClaim
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now