Skip to content

Instantly share code, notes, and snippets.

@jgadjetx
Last active April 14, 2020 11:44
Show Gist options
  • Save jgadjetx/221912170756b56533e2ca247f7324c7 to your computer and use it in GitHub Desktop.
Save jgadjetx/221912170756b56533e2ca247f7324c7 to your computer and use it in GitHub Desktop.
getMeters SQL Procedure
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
@jgadjetx
Copy link
Author

1st

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment