Created
April 14, 2018 21:27
-
-
Save alexandrebl/d8dc511b6fe5cc9ffc352114ea487e5d to your computer and use it in GitHub Desktop.
SQL Server Batch Writter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IF OBJECT_ID('dbo.Nums') IS NOT NULL | |
| DROP TABLE dbo.Nums; | |
| GO | |
| CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY); | |
| DECLARE @max AS INT, @rc AS INT; | |
| SET @max = 1000000000; | |
| SET @rc = 1; | |
| INSERT INTO Nums VALUES(1); | |
| WHILE @rc * 2 <= @max | |
| BEGIN | |
| INSERT INTO dbo.Nums SELECT n + @rc FROM dbo.Nums; | |
| SET @rc = @rc * 2; | |
| END | |
| INSERT INTO dbo.Nums | |
| SELECT n + @rc FROM dbo.Nums WHERE n + @rc <= @max; | |
| DECLARE @s AS DATETIME, @e AS DATETIME; | |
| SET @s = '19800101'; | |
| SET @e = '21061231'; | |
| SELECT @s + n - 1 AS dt | |
| FROM dbo.Nums | |
| WHERE n <= DATEDIFF(day, @s, @e) + 1; | |
| GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment