This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @Date date = getdate() | |
select | |
previous_month_bom = dateadd(month, datediff(month, 0, @Date) - 1, 0) --previous_month_bom | |
,previous_month_eom = dateadd(day, -1, dateadd(month, datediff(month, 0, @Date), 0)) -- previous_month_eom | |
,bom = dateadd(month, datediff(month, 0, @Date), 0) -- bom | |
,eom = dateadd(month, datediff(month, 0, @Date) + 1, -1) -- eom | |
,next_bom = dateadd(month, datediff(month, 0, @Date) + 1, 0) -- next_bom | |
,next_eom = dateadd(day, -1, dateadd(month, datediff(month, 0, @Date) + 2, 0)) -- next_eom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if object_id('tempdb..#Awesome') is not null | |
drop table #awesome; | |
create table #awesome | |
( | |
unique_join_k int | |
,process varchar(10) | |
,start_date date | |
,end_date date | |
,grouper_id as convert(uniqueidentifier, hashbytes('sha1', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************* | |
identifying gaps on a month | |
*******************************************************/ | |
if object_id('tempdb..#accounts') is not null | |
drop table #accounts; | |
-- Starting Point | |
select | |
'Starting Result Set' as query_description | |
,x.account |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
,create_date datetime2(3) not null default getdate() | |
,create_by_user varchar(50) default suser_sname() not null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------- obtain information on traces running ------------------------- | |
select | |
trace_id = id | |
,is_rowset | |
,trace_name = reverse(left(reverse(path), | |
charindex('\', reverse(path), | |
1) - 1)) | |
,trace_duration = | |
case | |
when stop_time is not null then 'Duration (min): ' + convert(varchar(10), datediff(minute, start_time, stop_time), 120) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create procedure test2 | |
@id int = 0, | |
@col1 int = 0, | |
@col2 int = 0 | |
as | |
begin | |
set nocount on | |
declare @sql nvarchar(255), @cond nvarchar(255) | |
set @sql = 'select id, col1, col2 from or_test ' | |
set @cond = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create unique nonclustered index ix_nc_CoveringIndex on or_test (id, col1, col2) with drop_existing; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Detecting and reducing VLFs in SQL Server 2008 | |
-- Glenn Berry | |
-- June 2010 | |
-- http://glennberrysqlperformance.spaces.live.com/ | |
-- Twitter: GlennAlanBerry | |
--select db_name(), * from sys.database_files | |
declare @DbName sysname = db_name() | |
,@Dt varchar(30) = convert(varchar(30), getdate(), 121) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance force | |
#NoEnv | |
#Persistent | |
SetWorkingDir %A_ScriptDir% | |
SetTitleMatchMode, Slow | |
SetTitleMatchMode,2 | |
DetectHiddenWindows, On |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************* | |
test data to work with | |
*******************************************************/ | |
if object_id('tempdb..#sample') is not null | |
drop table #sample; | |
select | |
* | |
into #sample | |
from | |
( |
OlderNewer