将时间和数字相乘作为 WAITFOR DELAY 中的总时间
multiplying time and number to be used as total time in WAITFOR DELAY
我想使用WAITFOR DELAY 'hh:mm:ss'但是里面的时间必须是具体的。我乘以两件事:
1) WAITFOR 中的时间值始终为“00:00:05”
2) 这是一个将用作参数的数字,例如@Count = 5.
我该怎么做才能实现这一目标?
我尝试了以下无效的代码:
declare @Count int;
set @Count = 5;
@Count * WAITFOR DELAY '00:00:05'
我希望上述查询的输出为 00:00:25,但它的错误是:
Incorrect syntax near '@Count'
请帮忙。
干杯
这应该有效:
DECLARE @seconds INT, @count INT, @delay VARCHAR(8);
SET @count = 3;
SET @seconds = 5;
SET @delay = CONVERT(VARCHAR(8), DATEADD(MILLISECOND, @seconds * @count * 1000, 0), 114);
WAITFOR DELAY @delay;
我想使用WAITFOR DELAY 'hh:mm:ss'但是里面的时间必须是具体的。我乘以两件事:
1) WAITFOR 中的时间值始终为“00:00:05”
2) 这是一个将用作参数的数字,例如@Count = 5.
我该怎么做才能实现这一目标?
我尝试了以下无效的代码:
declare @Count int;
set @Count = 5;
@Count * WAITFOR DELAY '00:00:05'
我希望上述查询的输出为 00:00:25,但它的错误是:
Incorrect syntax near '@Count'
请帮忙。
干杯
这应该有效:
DECLARE @seconds INT, @count INT, @delay VARCHAR(8);
SET @count = 3;
SET @seconds = 5;
SET @delay = CONVERT(VARCHAR(8), DATEADD(MILLISECOND, @seconds * @count * 1000, 0), 114);
WAITFOR DELAY @delay;