我习惯于在 MS SQL 中工作,并且正在努力让这个 mySql 存储过程正常工作!
我知道有数据要提取,但没有返回。
DELIMITER //
/* Author: Jessie Brown
Date: 8/17/13
Notes: Template Creation
Comments: Comments created in the header area will NOT be stored in the database write
Comments created AFTer the begin statement will be retained within the database write
*/
-- checks to see if stored procedure exists
-- if exists the procedure is dropped and recreated
DROP PROCEDURE IF EXISTS `reportLogExceptions`//
-- Creates new procedure
CREATE PROCEDURE reportLogExceptions (IN logId varchar(50),
IN groupId varchar(50),
IN fromDate varchar (50),
IN toDate varchar(50))
BEGIN
/*
report name: Log Exceptions
Test Query: CALL reportLogExceptions('1','1','1378385650','1378472050')
--------------------------------------------------------------------------
Declare variables*/
DECLARE logInS varchar(50);
DECLARE groupIdS varchar (50);
/*
Sets the variables to use for the SELECT query
*/
CASE
WHEN logInS = '-1' THEN
SET logInS = ''%'';
ELSE SET logInS = logInS;
END CASE;
CASE
WHEN groupIdS = '-1' THEN
SET groupIdS = ''%'';
Else SET groupIdS = groupIdS; END Case;
SELECT g.groupId,g.name AS groupName,l.logId,l.name AS logName, i.itemID,
i.name AS itemName, le.userName,completed, i.optimalMin,i.optimalMax ,value
FROM groups g
JOIN LOGS l ON g.groupID = l.groupId
JOIN logExceptions le ON l.logID = le.logID
JOIN items i ON l.logId = i.logId
WHERE l.logID LIKE logInS
AND g.groupID LIKE groupIdS
AND le.completed
BETWEEN FROM_UNIXTIME(fromDate / 1000)
AND FROM_UNIXTIME (toDate / 1000);
END//
DELIMITER ;
调用我正在使用的存储过程
CALL reportLogExceptions('-1','-1',' 1359676800','1362095999')