This file contains 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
SELECT | |
CAST(CONVERT(VARCHAR(10),GETDATE(),110) AS DATETIME) AS 'Today Start' | |
,DATEADD(s,-1,CONVERT(VARCHAR(10),GETDATE()+1,101)) AS 'Today End' | |
,CAST(DATEDIFF(dd,0,GETDATE()-1) AS DATETIME) AS 'Yesterday Start' | |
,DATEADD(s,-1,DATEADD(dd, DATEDIFF(dd,0,GETDATE()),0)) AS 'Yesterday End' | |
,CONVERT(VARCHAR(10), (DateAdd(DD, - 1 * (datepart(dw, GETDATE())), GETDATE() + 1)), 110) AS 'Week to Date Start' | |
,DATEADD(s,-1,DATEADD(dd, DATEDIFF(dd,0,GETDATE()),0)) AS 'Week to Date End' | |
,CONVERT(VARCHAR(10), (DateAdd(DD, - 1 * (6 + datepart(dw, GETDATE())), GETDATE())), 120) AS 'Prior Week Start' | |
,CONVERT(VARCHAR(10), (DateAdd(DD, -1 * (datepart(dw, GETDATE())), GETDATE())), 120) + ' 23:59:59' AS 'Prior Week End' | |
,CAST(DATEDIFF(dd,0,GETDATE()-7) AS DATETIME) AS 'Last 7 Days Start' |
This file contains 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
SELECT avg_fragmentation_in_percent, index_type_desc, index_id | |
FROM | |
sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL , null) | |
WHERE | |
OBJECT_NAME(OBJECT_ID)='Incident' | |
AND OBJECT_SCHEMA_NAME(OBJECT_ID)='dbo' |
This file contains 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
UPDATE SN | |
SET SN.PermanentRefcount = SN.PermanentRefcount - 1 | |
FROM | |
[ReportServerTempDB].dbo.SnapshotData AS SN | |
INNER JOIN [ReportServerTempDB].dbo.ExecutionCache AS EC ON SN.SnapshotDataID = EC.SnapshotDataID | |
INNER JOIN Catalog AS C ON EC.ReportID = C.ItemID | |
WHERE C.Path LIKE '%%' | |
DELETE EC | |
FROM |
This file contains 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
/*What is running?*/ | |
SELECT | |
program_name AS 'Program Name' | |
,count(*) AS 'Running Processes' | |
FROM master..sysprocesses | |
WHERE | |
ecid=0 | |
GROUP BY program_name | |
/*CPU processing*/ |
This file contains 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 | |
@table_name sysname = NULL -- Specify table name | |
, @partitioned_tables bit = NULL -- NULL: all tables; 0: un-partitioned tables; 1: partitioned tables | |
, @aligned_indexes bit = NULL -- NULL: all indexes; 0: un-aligned indexes; 1: aligned indexes | |
, @right_aligned bit = NULL -- NULL: all partition functions; 0: left-aligned partition functions; 1: right-aligned partition functions | |
, @index_types smallint = NULL -- NULL: all indexes; 0: heaps; 1: clustered indexes; 2: heaps and clustered indexes; 3: non-clustered indexes | |
, @debug bit = 0 -- 0: dynamic SQL statement is not printed; 1 dynamic SQL statement is printed | |
SET NOCOUNT ON | |
SET XACT_ABORT ON |
This file contains 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 TABLE SubscriptionEmailList ( | |
RowID INT IDENTITY (1,1) | |
,ReportName VARCHAR(200) | |
,SubscriptionDescription VARCHAR(200) | |
,JobID VARCHAR(40) | |
,TO VARCHAR(4000) | |
,CC VARCHAR(4000) | |
,BCC VARCHAR(4000) | |
,ReplyTo VARCHAR(4000) | |
,IncludeReport VARCHAR(5) |
This file contains 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
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | |
SELECT * FROM LinkedServer.Database.dbo.Table | |
--Set back to original isolation level. | |
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; |
This file contains 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 @string VARCHAR(255) | |
SET @string='Insert String You Are Searching' | |
/*Drop temp table if already exists in connection.*/ | |
IF OBJECT_ID('tempdb..#data') IS NOT NULL DROP TABLE #data | |
/*Gather Data*/ | |
SELECT | |
DISTINCT | |
CASE sysobjects.TYPE |
This file contains 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
/*SQL 2000 Find Column*/ | |
SELECT | |
SO.NAME AS 'Table Name' | |
,SC.NAME AS 'Column Name' | |
,SM.TEXT AS 'Default Value' | |
FROM dbo.sysobjects SO (NOLOCK) | |
INNER JOIN dbo.syscolumns SC (NOLOCK) ON (SO.id = SC.id) | |
LEFT JOIN dbo.syscomments SM (NOLOCK) ON (SC.cdefault = SM.id) | |
WHERE | |
SO.xtype = 'U' |
This file contains 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
USE ReportServer | |
SELECT | |
C.Name AS ReportName | |
,CASE | |
WHEN NEXT_RUN_DATE > 0 | |
THEN DATEADD(N,(NEXT_RUN_TIME%10000)/100 | |
,DATEADD(HH,NEXT_RUN_TIME/10000 | |
,CONVERT(DATETIME,CONVERT(VARCHAR(8),NEXT_RUN_DATE),112))) | |
ELSE CONVERT(DATETIME,CONVERT(VARCHAR(8),'19000101'),112) |