Skip to content

Instantly share code, notes, and snippets.

View DanielLoth's full-sized avatar

Daniel Loth DanielLoth

View GitHub Profile
@DanielLoth
DanielLoth / sql.sql
Created April 11, 2019 05:50
Get SQL object code
--select text from Payroll.sys.syscomments where id = 55086;
select * from sys.sql_modules where [object_id] = 55086;
select value from STRING_SPLIT(
(select [definition] from Payroll.sys.sql_modules where [object_id] = 55086), char(10));
select value from STRING_SPLIT(
(select replace([definition], char(13), '') from Payroll.sys.sql_modules where [object_id] = 55086), char(10));
@DanielLoth
DanielLoth / 1 - SharePoint table PIVOT.sql
Last active January 22, 2018 03:59
SharePoint table PIVOT
with CommaSeparatedColNames as (
select
TABLE_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION,
NUMERIC_SCALE,
ListIdColName,
ColNameList,
TPrefixedColNameList,
@DanielLoth
DanielLoth / On negotiating salary
Last active January 12, 2018 14:24
On negotiating salary
# Negotiating salary
https://www.reddit.com/r/personalfinance/comments/7psra0/reminder_never_tell_hr_how_much_you_make_or_are/
-----
Reddit user sadakxp (https://www.reddit.com/user/sadakxp) made this post:
Here's why this is not fair and what you should do about it, as a person interviewing.
@DanielLoth
DanielLoth / 0 - T-SQL auditing with triggers.sql
Last active January 11, 2018 12:15
T-SQL auditing with triggers
----------------------------------------------------------------------------------------------------
-- AUDITING WITH TRIGGERS
-- Written by Daniel Loth
----------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Populate a numbers table
--------------------------------------------------------------------------------
drop table if exists Number
go
@DanielLoth
DanielLoth / gist:2aaeac480cb9f7d09d9d9c1af5de5218
Created January 10, 2018 00:23
dotnet core project generation
dotnet new mvc -o MyProject
cd MyProject
REM CodeGenerators.Mvc added as package
dotnet add package "Microsoft.VisualStudio.Web.CodeGeneration.Design"
dotnet add package "Microsoft.VisualStudio.Web.CodeGenerators.Mvc"
REM CodeGeneration.Tools added as reference (not package) as it is tooling.
dotnet add reference "Microsoft.VisualStudio.Web.CodeGeneration.Tools"

GitHub repository

https://github.com/codesmithtools

Files of interest

All ****.zip files contain entire application templates.

This one actually creates SQL from the schema:

@DanielLoth
DanielLoth / SQL Server data pivot (rows to columns).sql
Last active November 30, 2017 07:14
SQL Server data pivot (rows to columns)
-- Based on this article: http://modern-sql.com/use-case/pivot
set nocount on
declare @Table table (
TableName char(20),
AttributeName char(20),
AttributeValue char(20),
-- Mandatory: Each attribute must appear precisely once for each element.
@DanielLoth
DanielLoth / All the kings horses and all the kings men.txt
Created October 24, 2017 23:27
All the kings horses and all the kings men.txt
-----BEGIN CERTIFICATE-----
N3q8ryccAARv0zvW0fUAAAAAAAAkAAAAAAAAAJ7EOroM7Zc0a6+nStey+OM7CfYN
jOFPik6bvYw80OCK9XtdvCpjNhqVOcmqH8nm3wSpBid2RCt/kOxnevEbrGAxe4oA
JOFnI+T2J25XphO9QATnd62Sassxl1ci57iiYMpVW3ef3/pFXUpFAqanMl65w6Ie
GKVyZZVr+Rk3esLMNfOKFo73yqUxflnGUfrI/fXRK0WbULgOGWTlIoIZ/4ahEbgP
cNmJNeRq+cXq43O6LXrOZsli2rQymuvO6nBS5uqgE/nFV3aiWMhZIiZUo64rDL2a
l1WYIHKAgI/02hDCOKyBhNIEHq2aRrtxBla/rOtYvmOxttVD1l4ZPYyowcg2AShc
kafOkU4dd5TTucc9dZpHqIRxCwvvhZ3kvmThakEn0LADSDr3B19Hnil2jsYtfkQ3
fq/ldPQJD/DxjGmolifwBlx3Wh5OVDq7u72bMmHOtHjchrc0AFo+0tDeXGH1q9rk
Amqe9bwRjf1fuptEzYqK6lTmEQCiEn+ao/XCqkgaIAvWhG5FFIElWb/tlve9azqN
@DanielLoth
DanielLoth / SQL Server - Object dependency queries.sql
Last active October 24, 2017 23:16
SQL Server - Object dependency queries
IF OBJECT_ID('tempdb.dbo.#tempdep', 'U') IS NOT NULL
DROP TABLE #tempdep;
CREATE TABLE #tempdep (objid int NOT NULL, objname sysname NOT NULL, objschema sysname NULL, objdb sysname NOT NULL, objtype smallint NOT NULL)
exec sp_executesql N'
INSERT INTO #tempdep
SELECT
tbl.object_id AS [ID],