Skip to content

Instantly share code, notes, and snippets.

View matthew-n's full-sized avatar

Matt N. matthew-n

  • Houston, Tx
View GitHub Profile
@matthew-n
matthew-n / serialization_xml.sql
Last active December 28, 2020 21:59
MSSQL tsql xml shaping
/*
Descriptions: reference for all the xml shapping I've learned
Author: Mattehw Naul
Explanation:
for each person do a correlated query for phone numbers,
format them mixing attributes and element values,
serialize to xml with "TYPE" so that we return on column of type XML root tag (phonelist)
name the cross apply result,
when phonelist(col) is null add nil phonelist node
@matthew-n
matthew-n / sierpinskis_tri.sql
Created June 29, 2016 14:29
A T-SQL implementation of Sierpinski's Triangles, just to see if I could do it.
/*
Description: A T-SQL implementation of Sierpinski's Triangles, just to see if I could do it.
Requires: SQL Server 2012
Inspired by: Alastair Aitchison SQLCLR implementation http://alastaira.wordpress.com/2012/03/06/drawing-fractals-with-sql-server-spatial/
Author: Matthew Naul
*/
DECLARE
@itrations INT = 12,
@seed geometry = geometry::STGeomFromText ('LINESTRING (9 12, 0 0, 18 0, 9 12)',0);
@matthew-n
matthew-n / JobAgent_SQLJobAgentScheduleTimeline_dataset.sql
Last active August 29, 2015 14:15
Replacement query for Job Steps Execution History by Ibrahim Naji
SELECT
name
-- added Days Back to use a fitler aginst the user input
,DATEDIFF(DAY,CONVERT(DATE, calc.run_date),GETDATE()) AS DaysBack
,CONVERT( DATETIME, calc.run_date + SPACE(1) + calc.run_time) AS start_time
-- using seconds here as I had a problem with times over 24 hrs
,DATEADD(SECOND, jh.run_duration, CONVERT( DATETIME, calc.run_date + SPACE(1) + calc.run_time)) AS end_time
,run_status
,instance_id
FROM msdb.dbo.sysjobhistory jh
{
function extractOptional(optional, index) {
return optional ? optional[index] : null;
}
function optionalList(value) {
return value !== null ? value : [];
}
}