Solved

mysql sql statement

Posted on 2011-03-06
9
254 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
Comment Utility
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
Comment Utility
can you please give your table structure for
product & claimdetail


0
 

Author Comment

by:teera
Comment Utility
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
Comment Utility
try this
UPDATE product SET product.ProductQuantity = (product.ProductQuantity - claimdetail.quantity) WHERE cast ( product.ProductId as int)  = claimdetail.quantity
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:teera
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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