Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strvmarv/cd6abd4769c657c4903ce7fb9f8b518d to your computer and use it in GitHub Desktop.
Save strvmarv/cd6abd4769c657c4903ce7fb9f8b518d to your computer and use it in GitHub Desktop.
CREATE PROCEDURE [dbo].[sproc_Imagination_TruncatePartitions]
@start DATETIME,
@end DATETIME
AS
BEGIN
SET NOCOUNT ON;
DECLARE @partitions TABLE (Number SMALLINT)
INSERT INTO @partitions SELECT Number FROM dbo.udf_GetDayOfTheYearRange_FromDate(@start, @end)
DECLARE @cnt INT = 0;
SELECT @cnt = COUNT(1) FROM @partitions
WHILE @cnt > 0
BEGIN
DECLARE @partition SMALLINT
SELECT TOP (1) @partition = Number FROM @partitions
TRUNCATE TABLE Imagination_Partitioned WITH (PARTITIONS(@partition))
DELETE TOP(1) FROM @partitions
SELECT @cnt = COUNT(1) FROM @partitions
END
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment