Skip to content

Instantly share code, notes, and snippets.

@chilismaug
chilismaug / ToJSON.sql
Created April 14, 2020 12:08
Phil Factor's SQL Table to JSON converter function
CREATE FUNCTION ToJSON
(
@Hierarchy Hierarchy READONLY
)
/*
the function that takes a Hierarchy table and converts it to a JSON string
Author: Phil Factor
Revision: 1.5
@chilismaug
chilismaug / JSONHierarchy_test.sql
Last active September 16, 2021 14:49
Phil Factor's Hiearchy Table function example - for making JSON via XML with T-SQL before MSSS2016
create TABLE #hierarchy
(
element_id INT IDENTITY(1, 1) NOT NULL, /* internal surrogate primary key gives the order of parsing and the list order */
parent_ID INT,/* if the element has a parent then it is in this column. The document is the ultimate parent, so you can get the structure from recursing from the document */
Object_ID INT,/* each list or object has an object id. This ties all elements to a parent. Lists are treated as objects here */
NAME NVARCHAR(2000),/* the name of the object */
StringValue NVARCHAR(MAX) NOT NULL,/*the string representation of the value of the element. */
ValueType VARCHAR(10) NOT null /* the declared type of the value represented as a string in StringValue*/
)
@chilismaug
chilismaug / predicates-terms-propositions.md
Last active November 4, 2019 17:01
Categorical Proposition Notes for SQL Study

Categorical Propositions for SQL Study

Name IS-A HAS-A CAN-BE-A WHADEY Heckin' Deal???
Proposition Assertion Predicate A proposition is the contents of an assertion which can be true or false. One of two propositions contains a term called a predicate that can be used to support the conclusion of a syllogism. Sep 9, 2016 https://philosophy.stackexchange.com If all of a predicate' s variables are bound, the resulting formula is a proposition. (WikiDiff) an instance of a ' predicate whose terms are all constant — e.g., P(2,3) — acts as a proposition.
Assertion Predicate True result; Affirmation Proposition assertion is (computing) a statement in a program asserting a condition expected to be true at a particular point. https://wikidiff.com/predicate/assertion
Predicate E
@chilismaug
chilismaug / Howmanycolumns.sql
Last active October 2, 2019 14:45
Horrible T-SQL hack to count columns without asking the system tables
-- how many columns in my table?
-- have to count null elements too
DECLARE @rowString AS VARCHAR(MAX)
DECLARE @StringToCount1 AS VARCHAR(100) = '</'
DECLARE @StringToCount2 AS VARCHAR(100) = '/>'
DECLARE @StringCount AS INT
DECLARE @ColCount AS INT
SELECT @rowString = (SELECT TOP 1 * FROM PE_CS_CUBE ORDER BY LASTUPDATED DESC FOR XML PATH, ELEMENTS XSINIL )
SET @StringCount = (LEN(@rowString) - LEN(REPLACE(@rowString, @StringToCount1,'')))/COALESCE(NULLIF(LEN(@StringToCount1), 0), 1)
+ (LEN(@rowString) - LEN(REPLACE(@rowString, @StringToCount2,'')))/COALESCE(NULLIF(LEN(@StringToCount2), 0), 1)
@chilismaug
chilismaug / frmReadXML.frm
Created May 24, 2019 18:36
vb easy steps p152 - Reading XML files - done in Excel VBA
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmReadXML
Caption = "Read XML Data"
ClientHeight = 4920
ClientLeft = 120
ClientTop = 465
ClientWidth = 9165
OleObjectBlob = "frmReadXML.frx":0000
StartUpPosition = 1 'CenterOwner
End
@chilismaug
chilismaug / vba-update-checklist.md
Last active September 22, 2022 00:24
vba-update-checklist : TDR_OPNCS_BYPHS_N_STAT_RPT_WEB

Implement SubZero, cleanup

  • Declarations, Inits, Drop-ins

    • Option Explicit
    • SubZero: remove/import version with gstrLogPath fix
    • update SubZero prologue constant to use G rather than D or I for WriteLog
    • add WriteLog as Public, not Private
    • Public iLogIndex As Integer
  • Search and destroy

@chilismaug
chilismaug / vba-update-cookbook.md
Last active May 21, 2019 13:53
Subzero-win10-VBA-update-cookbook

Main Goals

Always add

Option Explicit

Make sure to use the May 8 version of SubZero with a GetCentralLogFilePath function that trims the extra quotes from the variant string value when fetching Central Log Path

 gstrLogPath
' from https://vba-corner.livejournal.com/4623.html
'Before you can do anything with the Internet Explorer, of course you'll need one, and you'll need something to address it. The following function achieves exactly this by creating a new instance of the Internet Explorer and returning a pointer to it.
'returns new instance of Internet Explorer
Function GetNewIE() As SHDocVw.InternetExplorer
'create new IE instance
Set GetNewIE = New SHDocVw.InternetExplorer
'start with a blank page
GetNewIE.Navigate2 "about:Blank"
End Function
@chilismaug
chilismaug / vba-fu-factors.md
Created May 7, 2019 13:44
VBA integrations (other apps) touched on @ 53

BAE Detica Document Direct Blue Zone - Rocket Datawatch Monarch SAS IE web scrappy scrape tools

@chilismaug
chilismaug / wordcounter.bas
Last active February 23, 2023 16:47
vba word frequency app with dictionary and value sort
Option Explicit
Public txtFileName As String
Sub Mainline()
Call openDialog
Call GetWordsToOccurencesDict
End Sub