我正在使用Notepad ++并尝试在.bat中创建一个有限循环,而不必一遍又一遍地编写相同的命令。我正在研究一个公式
set x=0
:A
set y=1
echo %random% %random%%random% %random% %random% %random% %random% %random% %random% %random% %random%
set Z=%x%+%y%
goto :A until %Z% = 50
...但每次它回到:A
时,Z
都不会保持它已经获得的值。有没有办法可以使线性增长直到Z=50
1}}?
答案 0 :(得分:1)
我相信这是你要做的事。
@Echo off
set Z=1
:A
echo %random% %random%%random% %random% %random% %random% %random% %random% %random% %random% %random%
set /A Z+=1
IF NOT "%Z%"=="50" goto :A
pause
答案 1 :(得分:1)
...并使用评论中提到的DECLARE @T TABLE
(
AccountId INT,
UpdateDate DATETIME
)
INSERT INTO @T
VALUES
(123,'11/1/2017 08:00:00:000'),
(123,'11/1/2017 20:00:00:000'),
(123,'11/2/2017 08:00:00:000'),
(456,'11/1/2017 08:00:00:000'),
(456,'11/1/2017 14:00:00:000'),
(456,'11/1/2017 20:00:00:000'),
(789,'11/1/2017 08:00:00:000'),
(789,'11/2/2017 08:00:00:000')
;WITH CTE
AS
(
SELECT
SeqNo = ROW_NUMBER() OVER(PARTITION BY AccountId,CAST(UpdateDate AS DATE) ORDER BY UpdateDate),
*
FROM @T
)
SELECT
*
FROM CTE C1
WHERE EXISTS
(
SELECT 1 FROM CTE WHERE AccountId = C1.AccountId AND SeqNo > 1 AND CAST(UpdateDate AS DATE) = CAST(c1.UpdateDate AS DATE)
)
:
For /L