Skip to content

Instantly share code, notes, and snippets.

@mjswart
mjswart / birth_of_venus.sql
Created May 31, 2023 14:44
Birth of Venus
SELECT geometry::STGeomFromText('GEOMETRYCOLLECTION(
POLYGON((0.0 -312.8,1.9 -308.7,3.9 -304.7,6.6 -301.4,10.5 -299.3,11.4 -299.9,12.3 -300.5,13.4 -300.9,15.0 -300.8,20.1 -291.5,23.1 -280.1,26.7 -269.3,33.7 -261.8,32.5 -263.3,31.3 -264.7,30.3 -266.4,29.8 -268.6,26.5 -274.3,24.5 -281.3,24.2 -288.9,26.0 -296.3,26.4 -296.9,26.6 -297.6,26.9 -298.2,27.5 -298.5,27.5 -298.7,27.5 -298.9,27.5 -299.1,27.5 -299.3,20.5 -302.1,13.8 -305.1,7.7 -308.8,2.7 -313.5,1.7 -313.5,0.8 -313.5,0.1 -313.3,0.0 -312.8)),
POLYGON((113.3 -96.8,113.0 -98.0,112.6 -99.1,112.2 -100.2,111.7 -101.2,109.8 -101.2,107.9 -101.2,106.2 -101.0,105.0 -100.4,105.5 -97.2,107.8 -95.5,110.8 -95.3,113.3 -96.8)),
POLYGON((117.0 -114.8,119.2 -114.1,121.9 -114.3,124.0 -115.5,124.5 -117.8,122.5 -117.2,120.7 -116.4,118.9 -115.6,117.0 -114.8)),
POLYGON((117.0 -60.8,120.0 -61.2,123.4 -62.5,127.3 -63.7,132.0 -63.8,131.8 -68.2,132.4 -72.8,133.0 -77.4,132.8 -81.8,131.4 -84.6,129.3 -87.4,127.6 -90.6,127.5 -94.6,129.0 -97.2,131.0 -98.2,133.2 -99.5,135.0 -103.0,
create procedure s_test
as
select 1 as one
into #ONE;
select * from #ONE;
go
-- Get estimated plan for the following:
-- highlight the next line in SSMS and press CTRL+L
@mjswart
mjswart / RugTriangles
Last active April 6, 2018 03:59
Count the triangles in the rug
<!DOCTYPE HTML>
<html>
<body>
<script>
function IsConnected(x1, y1, x2, y2) {
return (x1 == x2) ||
(y1 == y2) ||
(Math.abs(x1-x2) == Math.abs(y1-y2) && ((x1+y1)%2) == 0);
}
@mjswart
mjswart / xml example
Created August 3, 2017 14:21
xml example
declare @xml xml = N'
<root>
<blat x="abc1">asdf</blat>
<blat x="abc2">asdf</blat>
<blat x="def">asdf</blat>
<blat x="def">asdf</blat>
<blat y="abc">asdf</blat>
</root>';
select nodes.n.query('.')
@mjswart
mjswart / ssms_color_grid.sql
Created May 5, 2017 13:39
SQL Server Management Studio Colors for the Spatial Results Tab
use tempdb
go
create table #polygons
(
polygonShape varchar(max),
color int check (color between 1 and 100),
intensity int check (intensity between 1 and 5)
);
@mjswart
mjswart / Polly.sql
Created May 4, 2017 18:52
Scarlet Macaw
use tempdb
go
if (object_id('paths') is not null) drop table paths;
if (object_id('colorMapping') is not null) drop table colorMapping;
if (object_id('polygons') is not null) drop table polygons;
create table paths
(
color char(7),
@mjswart
mjswart / d2l.sql
Created May 1, 2017 00:13
Desire2Learn logo
use tempdb
go
if object_id('#polygons') is not null
drop table #polygons;
go
create table #polygons
(
polygonShape varchar(max),
color int check (color between 1 and 100),
@mjswart
mjswart / SSB.sql
Last active July 9, 2019 22:11
say can you see?
use tempdb
go
declare @xoffset numeric(7,3) = 90;
declare @yoffset numeric(7,3) = -164;
declare @scale_star numeric(7,3) = 250;
declare @scale_x numeric(7,3) = 250;
declare @scale_y numeric(7,3) = -210;
declare @stars_xml xml;
@mjswart
mjswart / BDay.sql
Created April 18, 2017 17:43
Guess whose birthday it is!
use tempdb
go
create table #polygons
(
polygonShape varchar(max),
color int check (color between 1 and 100),
intensity int check (intensity between 1 and 5)
);