Skip to content

Instantly share code, notes, and snippets.

View matt40k's full-sized avatar

Matt Smith matt40k

View GitHub Profile
@matt40k
matt40k / OlapQueryLog.sql
Created March 26, 2016 21:33
Create SSAS query log table SQL script
CREATE TABLE [dbo].[OlapQueryLog]
(
[MSOLAP_Database] NVARCHAR(255) NULL,
[MSOLAP_Path] NVARCHAR(400) NULL,
[MSOLAP_User] NVARCHAR(255) NULL,
[Dataset] NVARCHAR(4000) NULL,
[StartTime] DATETIME NULL,
[Duration] BIGINT NULL
)
@matt40k
matt40k / GetExcelFilesOnSharePoint.sql
Created March 16, 2016 12:34
TSQL for getting Excel files on SharePoint site
select
REPLACE((d.[DirName] +'/' + d.[LeafName]), ' ', '%20')
from
[dbo].[AllDocs] d
where
extension = 'xlsx'
and IsCurrentVersion = 1
and d.SiteId = (select Top 1 SiteId from dbo.AllWebs where FullUrl = '' order by TimeCreated desc)
@matt40k
matt40k / TestRelease.ps1
Created March 3, 2016 21:06
Example of creating a release on GitHub
$url = 'https://api.github.com/repos/simsbulkimport/simsbulkimport/releases'
$apiKey = '{{REMOVED}}'
$header = @{"Authorization"="token "+ $apiKey}
$content = @{tag_name="v1.0.0";target_commitish="master";name="v1.0.0";body="Description of the release";draft=$false;prerelease=$false} | ConvertTo-Json
$r = Invoke-WebRequest -Uri $url -Method POST -Headers $header -Body $content
Write-Host $r.Content | ConvertFrom-Json
@matt40k
matt40k / tsql_schedule.sql
Created February 25, 2016 10:36
Scheduled sql jobs
--USE [msdb]
--GO
--DECLARE @schedule_id int
--EXEC msdb.dbo.sp_add_jobschedule @job_id=N'd00849dd-5001-4284-bd9e-bffce3ae0b98', @name=N'One-Time',
-- @enabled=1,
-- @freq_type=1,
-- @freq_interval=1,
-- @freq_subday_type=0,
-- @freq_subday_interval=0,
-- @freq_relative_interval=0,
@matt40k
matt40k / updateprefix.ps1
Created February 21, 2016 19:39
Update SSIS package prefixes
$dtsFiles = Get-ChildItem "C:\GIT\BusinessIntelligence\" -Filter *.dts -Recurse
Foreach($dtsFile in $dtsFiles)
{
Write-Host $dtsFile.FullName
$dtsContents = Get-Content $dtsFile.FullName
$dtsContents = $dtsContents -replace "SEQC_", "(SEQC) "
$dtsContents = $dtsContents -replace "SEQC - ", "(SEQC) "
$dtsContents = $dtsContents -replace "DFT_", "(DFT) "
@matt40k
matt40k / GetLatestSimsBulkImportVer.ps1
Created February 14, 2016 23:53
Returns the latest (public) build for SIMS Bulk Import (published on GitHub).
$url = "https://api.github.com"
$header = @{"ACCEPT"="application/json";"User-Agent"="SIMSBulkImport"}
$r = Invoke-WebRequest -Uri $url/repos/SIMSBulkImport/SIMSBulkImport/releases/latest -Method GET -Headers $header
$content = $r.Content | ConvertFrom-Json
Write-Host $content.name
@matt40k
matt40k / FindMatt40k.ps1
Created February 14, 2016 20:28
Find all files that have Matt40k in them
$projDir = "C:\Prjs\SIMSBulkImport\*"
$sbiFiles = Get-ChildItem -File $projDir -Recurse -Exclude *.dll, *.pdb, *.cache
Foreach($sbiFile in $sbiFiles)
{
$sbiContents = Get-Content $sbiFile.FullName | Select-String "Matt40k" -quiet
if ($sbiContents) {
Write-Host $sbiFile.FullName
}
@matt40k
matt40k / PreBuild.ps1
Last active February 14, 2016 09:28
PreBuild script for SIMS bulk Import
# Capita installer url \ password
$url = [Environment]::GetEnvironmentVariable("sims_url")
$password = [Environment]::GetEnvironmentVariable("sims_pwd")
# Get SIMS Application installation directory
$simsAppDir = [Environment]::GetEnvironmentVariable("SIMSDOTNETDIRECTORY")
Write-Host 'SIMS Application Directory: '$simsAppDir
New-Item -ItemType Directory -Force -Path C:\TEMP
$tmpDir = "C:\TEMP"
@matt40k
matt40k / BUILD.publish.xml
Created February 2, 2016 23:47
Example of a publish file to pass SqlCmdVariable to DacPac
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SqlCmdVariable Include="ODS">
<Value>ODS</Value>
</SqlCmdVariable>
<SqlCmdVariable Include="Staging">
<Value>Staging</Value>
</SqlCmdVariable>
</ItemGroup>
@matt40k
matt40k / YTD Reseller Sales Amount.mdx
Created January 27, 2016 20:23
Get YTD for Reseller Sales Amount regardless of the date hierarchy used (either Fiscal or Calendar)

Aggregate( PeriodsToDate ( [Date].[Fiscal].[Fiscal Year] ,[Date].[Fiscal].CurrentMember )

  • PeriodsToDate ( [Date].[Calendar].[Calendar Year] ,[Date].[Calendar].CurrentMember ) ,