Skip to content

Instantly share code, notes, and snippets.

View stevewithington's full-sized avatar
⛑️
solving problems

steve withington stevewithington

⛑️
solving problems
View GitHub Profile
@stevewithington
stevewithington / ssh-tutorial.md
Created September 2, 2022 19:33 — forked from slowkow/ssh-tutorial.md
ssh to a server without typing your password

How to ssh to a remote server without typing your password

Save yourself a few keystrokes. Follow the steps below:

  1. Run this Bash script on your laptop:

    #!/usr/bin/env bash
    

The hostname of your remote server.

@stevewithington
stevewithington / usp-create-temp-table-from-existing-table.sql
Created April 6, 2022 15:04
SQL: Create Temp Table From Existing Table
USE [someDb];
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP PROCEDURE IF EXISTS [dbo].[usp_CreateTempTableFromTable];
@stevewithington
stevewithington / update-field-to-null-if-string-in-filter-temp-table.sql
Created April 6, 2022 15:02
SQL: Update Field To NULL If String Found In Filter Strings Temp Table
DECLARE @filter_strings TABLE (
filter_string NVARCHAR(255) NOT NULL
);
INSERT INTO @filter_strings(filter_string)
VALUES ('test'), ('city'), ('state'), ('title'), ('street'), ('1'), ('-'), ('.'), ('na'), ('n/a'), ('x'), ('?'), ('unknown'), ('asdf'), ('abcd'), ('abc'), ('abd')
;
UPDATE [dbo].[someTable]
SET
[postal_code] =
@stevewithington
stevewithington / case-when-like-regex.sql
Last active April 6, 2022 14:57
SQL: CASE WHEN LIKE RegEx example
-- Update with RegEx
UPDATE t
SET
[someField] =
CASE
WHEN LEFT(t.[postal_code], 3) LIKE '%[a-z][0-9][a-z]%'
THEN 'Canadian Value'
WHEN LEFT(t.[postal_code], 3) LIKE '%[0-9][0-9][0-9]%'
THEN 'US Value'
ELSE NULL
@stevewithington
stevewithington / exec-list-of-stored-procs.sql
Created April 6, 2022 12:38
SQL: Execute a list of stored procedures
USE [someDb];
GO;
DECLARE @table Table (id INT IDENTITY(1,1), item NVARCHAR(255) NOT NULL)
;
INSERT INTO @table (item)
SELECT someColumn
FROM someConfigurationTable
@stevewithington
stevewithington / sql-server-row-count-for-db-tables.sql
Last active August 6, 2021 13:13
SQL Server Row Count for all Database Tables
-- SQL Server Row Count for all Database Tables
USE [SomeTable]
GO
DECLARE @QueryString NVARCHAR(MAX);
SELECT @QueryString =
COALESCE(@QueryString + ' UNION ALL ','')
+ 'SELECT '
@stevewithington
stevewithington / sql-kill-all-transactions.sql
Created August 6, 2021 12:55
Kill all transactions in a database during a restore to avoid issues with exclusive access.
-- Kill all transactions in a database during a restore to avoid issues with exclusive access.
DECLARE @SQL VARCHAR(8000)
SELECT @SQL=COALESCE(@SQL,'')+'Kill '+CAST(spid AS VARCHAR(10))+ '; '
FROM sys.sysprocesses
WHERE DBID=DB_ID('AdventureWorks')
PRINT @SQL --EXEC(@SQL) Replace the print statement with exec to execute
@stevewithington
stevewithington / bash-ansi-variables-colorized-echo-output.md
Created April 16, 2021 14:26
Bash ANSI Variables for Colorized Echo Output

Bash ANSI Variables for Colorized Echo Output

I wanted to be able to make some messaging stand out while running Azure Pipeline Builds. This is ultimately what worked for me.

Example Usage

Some simple examples of how to use the variables listed below.

One Color for the Entire Line

@stevewithington
stevewithington / get-total-average-row-counts.sql
Created April 7, 2021 16:03
SQL: Get total and average row count per table and/or database
/* SQL: Get total and average row count per table and/or database */
USE SomeDB;
GO
CREATE TABLE #counts
(
table_name varchar(255),
row_count int
)
@stevewithington
stevewithington / auto-increment-npm
Created March 30, 2021 22:43 — forked from LukePammant/auto-increment-npm
Auto-increment NPM package in Azure Pipelines and publish to Azure Artifacts
trigger:
branches:
include:
- develop
- master
paths:
include:
- ./
resources: