Last active
April 14, 2020 11:44
-
-
Save jgadjetx/221912170756b56533e2ca247f7324c7 to your computer and use it in GitHub Desktop.
getMeters SQL Procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DEFINER=`root`@`localhost` PROCEDURE `getMeters`(IN `count` INT(10), IN `page` INT(10), IN `meterNum` VARCHAR(255), IN `routebookID` VARCHAR(255)) | |
BEGIN | |
DECLARE offsetVar INT DEFAULT 0; | |
SET offsetVar = (page - 1) * count; | |
SELECT DISTINCT(ADDRESS.ADDRESSID), | |
METER.METERNUMBER, | |
METER_MASTER.UNITNUMBER, | |
ADDRESS.ADDRESSID, | |
METER.METERID, | |
METER.SERVICESCALE, | |
METER.ACCOUNTNUMBER, | |
ADDRESS.ADDRESS1, ADDRESS.ADDRESS2, ADDRESS.NAME, | |
METER.DIALINDICATOR, | |
METER.SEQUENCENUMBER, | |
METER.LASTMODIFIED | |
FROM | |
bcmm_qas.METER | |
INNER JOIN | |
METER_MASTER ON METER.METERNUMBER = METER_MASTER.METERNO | |
INNER JOIN | |
ADDRESS ON ADDRESS.ADDRESSID = METER.ADDRESSID | |
INNER JOIN | |
ROUTEBOOK ON ROUTEBOOK.ROUTEBOOKID = METER_MASTER.MBOOK | |
WHERE METER.INACTIVE = 1 | |
OR METER_MASTER.UNITNUMBER LIKE CONCAT('%',meterNum,'%') | |
OR METER.METERNUMBER LIKE CONCAT('%',meterNum,'%') | |
OR ADDRESS.ADDRESS2 LIKE CONCAT('%',meterNum,'%') | |
LIMIT offsetVar, count; | |
SELECT FOUND_ROWS() AS total; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1st