DECLARE @i INT = 0;
SELECT @count= Count(*) FROM {TABLE}
WHILE @i <= @count
BEGIN
SELECT * FROM {TABLE}
ORDER BY {COLUMN}
OFFSET @i ROWS
FETCH NEXT 1 ROWS ONLY
SET @i = @i + 1;
END
DECLARE @r INT = 5
DECLARE @i INT = 0
DECLARE @F varchar(max) = ''
WHILE @i < @r
BEGIN
DECLARE @j INT = 0
DECLARE @o varchar(max) = ''
WHILE @j < @r - @i - 1
BEGIN
SET @o = @o + ' '
SET @j += 1
END
DECLARE @k INT = 0
WHILE @k < @i + 1
BEGIN
SET @o = @o + ' *' -- '*'
SET @k += 1
END
SET @i += 1
SET @F = @F + @o + CHAR(13)
END
PRINT @F
日期:
DECLARE @d DATE = '2019-11-01'
WHILE @d < GETDATE()
BEGIN
PRINT @d
SET @d = DATEADD(DAY,1,@d)
END
PRINT 'n'
PRINT @d
DECLARE @myValue nvarchar(45);
DECLARE myCursor CURSOR FOR
SELECT [x]
FROM (Values ('Value1'),('Value2'),('Value3'),('Value4'))
as MyTable(x);
OPEN myCursor;
FETCH NEXT FROM myCursor INTO @myValue;
While (@@FETCH_STATUS = 0)
BEGIN
PRINT @myValue
FETCH NEXT FROM myCursor INTO @myValue;
END
CLOSE myCursor;
DEALLOCATE myCursor;