mssql loop

murkgom·2022년 11월 15일
0
DECLARE @fromDate DATETIME2(0)
DECLARE @toDate DATETIME2(0)
DECLARE @loopCount INT 
DECLARE @index INT
 
SET @loopCount = 0 
SET @index = 3000
SET @fromDate = '2022-10-14 00:00:00' 
SET @toDate = '2022-11-14 23:59:59'

 
--반복처리
WHILE (@loopCount <= @index)
BEGIN 	
	DECLARE @seconds INT = DATEDIFF(SECOND, @fromDate, @toDate)
	DECLARE @random INT = ROUND(((@seconds - 1) * RAND()), 0)
	
 	SELECT DATEADD(SECOND, @random, @fromDate);
    
    SET @loopCount = @loopCount + 1
    PRINT @loopCount
END 

0개의 댓글