--建立过程
CREATE PROCEDURE GetTime
@BeginTime VARCHAR(5),
@EndTime VARCHAR(5),
@RandTime VARCHAR(5) OUTPUT
AS
SET @RandTime=(SELECT SUBSTRING(CONVERT(VARCHAR,CONVERT(DATETIME,100/RAND(),120),120),12,5))
WHILE @RandTime<=@BeginTime or @RandTime>=@EndTime
SET @RandTime=(SELECT SUBSTRING(CONVERT(VARCHAR,CONVERT(DATETIME,100/RAND(),120),120),12,5))
GO
--执行示例
DECLARE @OutTime VARCHAR(5)
EXEC GetTime ‘05:00‘,‘20:00‘,@Outtime OUTPUT
SELECT @outtime