Hi
Bandi
I tried in your query not working . I mention below Query
CREATE TABLE `test`.`tbltest1` (
`id` INT NOT NULL AUTO_INCREMENT ,
`ShareNo` INT NULL ,
`Date` DATE NULL ,
`Recptamt` DECIMAL(18,2) NULL ,
`Payamt` DECIMAL(18,2) NULL ,
PRIMARY KEY (`id`) );
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-04-29', '17000.00', '0');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-01', '1000.00', '0');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-02', '10000.00', '0');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-03', '3000.00', '0');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-04', '1000.00', '0');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-04-29', '0', '1000.00');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-01', '0', '100.00');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-02', '0', '300.00');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-03', '0', '400.00');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2544, '2015-05-04', '0', '600.00');
INSERT INTO `test`.`tbltest1` (`ShareNo`, `Date`, `Recptamt`, `Payamt`) VALUES (2548, '2015-05-04', '0', '800');
But My Query This But not working can you alter this
CREATE DEFINER=`root`@`localhost` PROCEDURE `Testt`(in _FromDate date,_ToDate date,_shareno int)
BEGIN
SELECT @OpeningBal:= SUM(Recptamt)-SUM(Payamt) OpeningBal
FROM tbltest1
WHERE Date < _FromDate;
SELECT Date, Recptamt, Payamt, @OpeningBal +
Recptamt-Payamt +
COALESCE((SELECT SUM(Recptamt-Payamt) FROM tbltest1 AS s
WHERE s.Date < o.Date
and Date between _FromDate and _ToDate), 0) As Total , @OpeningBal as OpeningBal
FROM tbltest1 AS o
WHERE Date between @FromDate and @ToDate and shareno=_shareno
ORDER BY Date;
END
Mark as Answer if its helpful to you
Kumaraspcode2009@gmail.com
Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator