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 EXISTS(SELECT * FROM sys.indexes WHERE object_id = object_id('schema.tablename') AND NAME ='indexname') | |
DROP INDEX indexname ON SCHEMA.tablename; |
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 @tableName VARCHAR(256); | |
SET @tableName = 'dbo.ct_pstor'; | |
SELECT name AS Stats, | |
STATS_DATE(object_id, stats_id) AS LastStatsUpdate | |
FROM sys.stats | |
WHERE object_id = OBJECT_ID(@tableName) | |
and left(name,4)!='_WA_'; |
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
SET STATISTICS IO ON; | |
SET STATISTICS TIME 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
IF EXISTS ( | |
SELECT * | |
FROM sys.columns | |
WHERE object_id = OBJECT_ID(N'[dbo].[Person]') | |
AND name = 'ColumnName' | |
) | |
ALTER TABLE dbo.Person | |
ADD ColumnName VARCHAR(64) |
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
FROM - http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap | |
Let ConditionA Mean DateRange A Completely After DateRange B | |
(True if StartA > EndB) | |
Let ConditionB Mean DateRange A Completely Before DateRange B | |
(True if EndA < StartB) | |
Then Overlap exists if Neither A Nor B is true | |
( If one range is neither completely after the other, | |
nor completely before the other, then they must overlap) |
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 EXISTS(SELECT * FROM sys.views WHERE name = 'e_note' AND schema_id = SCHEMA_ID('dbo')) | |
DROP VIEW dbo.e_note | |
GO |
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
SELECT | |
name | |
FROM | |
ices.sys.tables | |
WHERE | |
name LIKE '%Line%' | |
AND is_ms_shipped = 0; |
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('MySproc', 'P') IS NOT NULL | |
DROP PROC MySproc | |
GO | |
CREATE PROC MySproc | |
AS | |
BEGIN | |
[CODE HERE] | |
END |
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..#TEMP') IS NOT NULL DROP TABLE #TEMP | |
--This will work since each delete is done as a single row | |
SELECT RowNum = ROW_NUMBER() OVER(ORDER BY ct_id), ct_id | |
INTO #TEMP | |
FROM ct_note where ntype_id IN('{d94f685c-84ec-49b2-8e0f-ebaf9f6e609f}', '{afbf6d79-6d77-41e6-8790-9505e9b9ed82}', '{6cad622d-c3b7-4907-b62a-a882902ee4e4}') | |
DECLARE @MaxRownum INT | |
SET @MaxRownum = (SELECT MAX(RowNum) FROM #TEMP) |
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
SELECT | |
FORMAT(GETDATE(), 'g'), | |
CONVERT(VARCHAR(32), CAST(GETDATE() AS DATE), 101) AS d, | |
REPLACE(REPLACE(RIGHT(CAST(GETDATE() AS DATETIME), 7), 'AM', ' AM'), 'PM', ' PM') AS t |