Skip to content

Instantly share code, notes, and snippets.

View shaneis's full-sized avatar
🎯
The mind isn't a cup to fill but a fire to feed...my whiskey cup is empty tho...

Shane O'Neill shaneis

🎯
The mind isn't a cup to fill but a fire to feed...my whiskey cup is empty tho...
View GitHub Profile
@shaneis
shaneis / NewLines_FileOutBasic.ps1
Last active July 26, 2017 16:21
New Lines File Out Basic
$NewLineQuery = 'SELECT Notes FROM dbo.NewLineNotes'
$InvSQLParams = @{
ServerInstance = '0738-5CG140G7T\SQLSERVER2K16'
Database = 'Pantheon'
Query = $NewLineQuery
}
Invoke-Sqlcmd @InvSQLParams |
Select-Object -Property Notes |
@shaneis
shaneis / OldStyleAddingConstraints.sql
Created July 21, 2017 08:38
Old Style Adding Constraints
USE Pantheon;
GO
DROP TABLE IF EXISTS dbo.CreateThenAlter;
CREATE TABLE dbo.CreateThenAlter
(
RBAR char(10)
);
GO
ALTER TABLE dbo.CreateThenAlter ADD CONSTRAINT CHK_CreateThenAlter_RBAR CHECK (RBAR IN ('good', 'bad'));
ALTER TABLE dbo.CreateThenAlter ADD CONSTRAINT DF_CreateThenAlter_RBAR DEFAULT ('good') FOR RBAR;
@shaneis
shaneis / NewStyleAddingConstraints.sql
Created July 21, 2017 08:46
New Style Adding Constraints
DROP TABLE IF EXISTS dbo.AllInLine;
CREATE TABLE dbo.AllInLine
(
CheckyMcCheckFace char(10)
CONSTRAINT CHK_AllInLine_CheckyMcCheckFace CHECK (CheckyMcCheckFace IN ('good', 'bad'))
CONSTRAINT DF_AllInLine_CheckyMcCheckFace DEFAULT ('good')
);
@shaneis
shaneis / NewLines_FileOutBasicSpecialChars.ps1
Created July 26, 2017 16:21
New Lines File Out Basic Special Char
$NewLineQuery = 'SELECT Notes FROM dbo.NewLineNotes'
$InvSQLParams = @{
ServerInstance = '0738-5CG140G7T\SQLSERVER2K16'
Database = 'Pantheon'
Query = $NewLineQuery
}
Invoke-Sqlcmd @InvSQLParams |
Select-Object -Property Notes |
@shaneis
shaneis / SubstringLengthError.ps1
Created August 10, 2017 09:28
Substring Length Error
#... get some results to work with...
$sqlcmdParams = @{
ServerInstance = 'localhost\SQLSERVER2K16'
Database = 'master'
Query = @'
SELECT TOP(10)
name
FROM dbo.spt_values
WHERE name IS NOT NULL
AND LEN(name) != 0
@shaneis
shaneis / Get-BackupFilesSize.ps1
Created August 30, 2017 16:06
Sums the sizes of ".bak", ".diff", and ".trn" files in a folder
Function Get-BackupFilesSizes {
$Bak = $Diff = $Trn = 0;
$Bak = (Get-ChildItem -File |
Where-Object { $_.Extension -eq '.bak' } |
Measure-Object -Property Length -Sum).Sum;
$Diff = (Get-ChildItem -File |
Where-Object { $_.Extension -eq '.diff' } |
Measure-Object -Property Length -Sum).Sum;
$Trn = (Get-ChildItem -File |
@shaneis
shaneis / Import-excel.ps1
Created September 11, 2017 16:41
Import Excel
function Import-Excel ($FolderPath, $XlsxFile, $Server, $Database, $Table) {
# Create an Excel workbook...
$Excel = New-Object -ComObject Excel.Application;
$Workbook = $Excel.WorkBooks.Open((Join-Path -Path (Convert-Path -Path $FolderPath) -ChildPath $XlsxFile));
$WorkSheet = $Workbook.WorkSheets.Item(1); # Thankfully only 1 sheet so this doesn't need to change...
$StartRow = 2; # ...ignore headers...
# Insert into a System.Data.DataTable...
$DataTable = New-Object -TypeName System.Data.DataTable;
$null = $DataTable.Columns.Add('DiscId', 'System.Int32');
@shaneis
shaneis / dbo_DiscCharacters.sql
Last active September 12, 2017 08:14
Disc Characters table create statement
CREATE TABLE dbo.DiscCharacters (
DiscId int IDENTITY(1, 1) NOT NULL,
Person varchar(50) NULL,
Job varchar(75) NULL,
Notes varchar(300) NULL
);
GO
@shaneis
shaneis / CreateTable_RunningTotals.sql
Last active October 9, 2017 12:40
Running Totals table create statement
CREATE TABLE dbo.RunningTotals (
SpentDate date NOT NULL,
SpentAmount smallmoney NOT NULL
);
GO
@shaneis
shaneis / InsertRunningTotals.sql
Last active October 9, 2017 12:46
Insert statements for dbo.RunningTotals
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (DATEADD(DAY, -1, GETDATE()), 50.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (DATEADD(DAY, -1, GETDATE()), 50.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (DATEADD(DAY, -1, GETDATE()), -75.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (DATEADD(DAY, -1, GETDATE()), 50.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (GETDATE(), 100.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (GETDATE(), 100.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (GETDATE(), -150.00);
INSERT INTO dbo.RunningTotals (SpentDate, SpentAmount) VALUES (GETDATE(), 100.00);