Skip to content

Commit 97c2ef6

Browse files
Darling Datagflpcantor31
authored andcommitted
Automation: Format and Build SQL File
1 parent 451e302 commit 97c2ef6

2 files changed

Lines changed: 123 additions & 106 deletions

File tree

Install-All/DarlingData.sql

Lines changed: 105 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Compile Date: 12/28/2025 14:49:57 UTC
1+
-- Compile Date: 01/03/2026 20:00:05 UTC
22
SET ANSI_NULLS ON;
33
SET ANSI_PADDING ON;
44
SET ANSI_WARNINGS ON;
@@ -264,7 +264,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
264264
@max_event_time datetime2(7),
265265
@dsql nvarchar(max) = N'',
266266
@mdsql_template nvarchar(max) = N'',
267-
@mdsql_execute nvarchar(MAX) = N'';
267+
@mdsql_execute nvarchar(max) = N'',
268+
@start_date_debug nvarchar(50),
269+
@end_date_debug nvarchar(50);
268270

269271
IF @azure = 1
270272
BEGIN
@@ -277,68 +279,38 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
277279
RAISERROR('Fixing parameters and variables', 0, 0) WITH NOWAIT;
278280
END;
279281

282+
/*
283+
Normalize dates to UTC offset for comparison with system_health events
284+
When dates are NULL, use SYSUTCDATETIME() which is already UTC
285+
When dates are provided, SWITCHOFFSET converts from any timezone to UTC
286+
This matches sp_QuickieStore pattern for handling date conversions
287+
*/
280288
SELECT
281289
@start_date =
282-
CASE
283-
WHEN @start_date IS NULL
284-
THEN
285-
DATEADD
286-
(
287-
MINUTE,
288-
DATEDIFF
289-
(
290-
MINUTE,
291-
SYSDATETIME(),
292-
GETUTCDATE()
293-
),
294-
DATEADD
295-
(
296-
DAY,
297-
-7,
298-
SYSDATETIME()
299-
)
300-
)
301-
ELSE
302-
DATEADD
303-
(
304-
MINUTE,
305-
DATEDIFF
306-
(
307-
MINUTE,
308-
SYSDATETIME(),
309-
GETUTCDATE()
310-
),
311-
@start_date
312-
)
313-
END,
290+
ISNULL
291+
(
292+
SWITCHOFFSET
293+
(
294+
@start_date,
295+
'+00:00'
296+
),
297+
DATEADD
298+
(
299+
DAY,
300+
-7,
301+
SYSUTCDATETIME()
302+
)
303+
),
314304
@end_date =
315-
CASE
316-
WHEN @end_date IS NULL
317-
THEN
318-
DATEADD
319-
(
320-
MINUTE,
321-
DATEDIFF
322-
(
323-
MINUTE,
324-
SYSDATETIME(),
325-
GETUTCDATE()
326-
),
327-
SYSDATETIME()
328-
)
329-
ELSE
330-
DATEADD
331-
(
332-
MINUTE,
333-
DATEDIFF
334-
(
335-
MINUTE,
336-
SYSDATETIME(),
337-
GETUTCDATE()
338-
),
339-
@end_date
340-
)
341-
END,
305+
ISNULL
306+
(
307+
SWITCHOFFSET
308+
(
309+
@end_date,
310+
'+00:00'
311+
),
312+
SYSUTCDATETIME()
313+
),
342314
@wait_round_interval_minutes = /*do this i guess?*/
343315
CASE
344316
WHEN @wait_round_interval_minutes < 1
@@ -408,33 +380,37 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
408380
OPTION(RECOMPILE);
409381
',
410382
@mdsql_template = N'
411-
IF OBJECT_ID(''{table_check}'', ''U'') IS NOT NULL
412-
BEGIN
413-
SELECT
414-
@max_event_time =
415-
ISNULL
383+
IF OBJECT_ID(''{table_check}'', ''U'') IS NOT NULL
384+
BEGIN
385+
SELECT
386+
@max_event_time =
387+
ISNULL
388+
(
389+
MAX({date_column}),
390+
DATEADD
391+
(
392+
MINUTE,
393+
DATEDIFF
416394
(
417-
MAX({date_column}),
418-
DATEADD
419-
(
420-
MINUTE,
421-
DATEDIFF
422-
(
423-
MINUTE,
424-
SYSDATETIME(),
425-
GETUTCDATE()
426-
),
427-
DATEADD
428-
(
429-
DAY,
430-
-1,
431-
SYSDATETIME()
432-
)
433-
)
395+
MINUTE,
396+
SYSDATETIME(),
397+
GETUTCDATE()
398+
),
399+
DATEADD
400+
(
401+
DAY,
402+
-1,
403+
SYSDATETIME()
434404
)
435-
FROM {table_check};
436-
END;
437-
';
405+
)
406+
)
407+
FROM {table_check};
408+
END;
409+
';
410+
411+
SELECT
412+
@start_date_debug = @start_date,
413+
@end_date_debug = @end_date;
438414

439415
IF @timestamp_utc_mode = 0
440416
BEGIN
@@ -1415,7 +1391,7 @@ AND ca.utc_timestamp < @end_date';
14151391

14161392
IF @debug = 1
14171393
BEGIN
1418-
RAISERROR('Executing collection SQL', 0, 0) WITH NOWAIT;
1394+
RAISERROR('Executing collection SQL for dates between %s and %s', 0, 0, @start_date_debug, @end_date_debug) WITH NOWAIT;
14191395
SET STATISTICS XML ON;
14201396
END;
14211397

@@ -31059,8 +31035,49 @@ SET IMPLICIT_TRANSACTIONS OFF;
3105931035
SET STATISTICS TIME, IO OFF;
3106031036
GO
3106131037

31038+
/*
31039+
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
31040+
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
31041+
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
31042+
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
31043+
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
31044+
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
31045+
31046+
██████╗ ███████╗██████╗ ██████╗ ██████╗
31047+
██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔═══██╗
31048+
██████╔╝█████╗ ██████╔╝██████╔╝██║ ██║
31049+
██╔══██╗██╔══╝ ██╔═══╝ ██╔══██╗██║ ██║
31050+
██║ ██║███████╗██║ ██║ ██║╚██████╔╝
31051+
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝
31052+
31053+
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
31054+
██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗
31055+
██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝
31056+
██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗
31057+
██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║
31058+
╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝
3106231059

31063-
CREATE OR ALTER PROCEDURE
31060+
Copyright 2026 Darling Data, LLC
31061+
https://www.erikdarling.com/
31062+
31063+
For usage and licensing details, run:
31064+
EXECUTE sp_QueryReproBuilder
31065+
@help = 1;
31066+
31067+
For working through errors:
31068+
EXECUTE sp_QueryReproBuilder
31069+
@debug = 1;
31070+
31071+
For support, head over to GitHub:
31072+
https://code.erikdarling.com
31073+
31074+
*/
31075+
31076+
IF OBJECT_ID(N'dbo.sp_QueryReproBuilder', N'P') IS NULL
31077+
EXECUTE (N'CREATE PROCEDURE dbo.sp_QueryReproBuilder AS RETURN 138;');
31078+
GO
31079+
31080+
ALTER PROCEDURE
3106431081
dbo.sp_QueryReproBuilder
3106531082
(
3106631083
@database_name sysname = NULL, /*the name of the database you want to look at query store in*/

sp_QueryReproBuilder/sp_QueryReproBuilder.sql

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SET ANSI_NULLS ON;
1+
SET ANSI_NULLS ON;
22
SET ANSI_PADDING ON;
33
SET ANSI_WARNINGS ON;
44
SET ARITHABORT ON;
@@ -10,27 +10,27 @@ SET STATISTICS TIME, IO OFF;
1010
GO
1111

1212
/*
13-
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
14-
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
15-
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
16-
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
17-
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
18-
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
19-
20-
██████╗ ███████╗██████╗ ██████╗ ██████╗
21-
██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔═══██╗
22-
██████╔╝█████╗ ██████╔╝██████╔╝██║ ██║
23-
██╔══██╗██╔══╝ ██╔═══╝ ██╔══██╗██║ ██║
24-
██║ ██║███████╗██║ ██║ ██║╚██████╔╝
25-
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝
26-
27-
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
13+
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
14+
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
15+
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
16+
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
17+
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
18+
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
19+
20+
██████╗ ███████╗██████╗ ██████╗ ██████╗
21+
██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔═══██╗
22+
██████╔╝█████╗ ██████╔╝██████╔╝██║ ██║
23+
██╔══██╗██╔══╝ ██╔═══╝ ██╔══██╗██║ ██║
24+
██║ ██║███████╗██║ ██║ ██║╚██████╔╝
25+
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝
26+
27+
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
2828
██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗
2929
██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝
3030
██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗
3131
██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║
3232
╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝
33-
33+
3434
Copyright 2026 Darling Data, LLC
3535
https://www.erikdarling.com/
3636
@@ -43,7 +43,7 @@ EXECUTE sp_QueryReproBuilder
4343
@debug = 1;
4444
4545
For support, head over to GitHub:
46-
https://code.erikdarling.com
46+
https://code.erikdarling.com
4747
4848
*/
4949

0 commit comments

Comments
 (0)