2017-03-01 36 views
1

我想根據存儲過程中的參數更改此SQL語句中的時間間隔。我想用三個不同的時間間隔:2天,8小時,1小時存儲過程中的條件時間間隔

CREATE DEFINER= 'dbshizzle' PROCEDURE `getData`(in sD text(17), in sT text(8)) 
BEGIN 
select stime, sval 
from tblNumber 
where sDix = 'allright' 
and timestamp >= now() - interval 1 day 
order by timestamp; 
END 

我應該使用IF語句與整型參數,或者文本參數?

回答

0

如何調整參數並將值傳遞爲小時?

CREATE DEFINER = 'dbshizzle' PROCEDURE `getData`(
    in in_sD text(17), -- should change to varchar 
    in in_sT text(8), -- should change to varchar 
    in in_hours int 
) 
BEGIN 
    select stime, sval 
    from tblNumber 
    where sDix = 'allright' 
    and timestamp >= now() - interval in_hours hour 
    order by timestamp; 
END;