Last active
January 1, 2016 13:29
-
-
Save eduardosilva/8151454 to your computer and use it in GitHub Desktop.
Scripts and helpful instructions regarding sql server
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 @StartDate DATETIME | |
DECLARE @EndDate DATETIME | |
SELECT | |
@StartDate = '2012-01-15',-- my start date | |
@EndDate = '2012-02-02' -- my end date; | |
; --(If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.) | |
WITH date_range(calc_date) AS ( | |
SELECT | |
@StartDate | |
UNION ALL | |
SELECT | |
DATEADD(DAY, 1, calc_date) | |
FROM date_range | |
WHERE | |
DATEADD(DAY, 1, calc_date) <= @EndDate) | |
SELECT calc_date FROM date_range; |
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
-- Script to data generation using the GO statement | |
GO | |
DECLARE @Index AS INT | |
DECLARE @IndexText AS VARCHAR(50) | |
SELECT | |
@Index = COUNT(1) | |
FROM | |
Customers WITH(NOLOCK) | |
SET @Index = @Index + 1 | |
SET @IndexText = CAST(@Index AS VARCHAR) | |
INSERT INTO Customers (Name, Email) | |
VALUES('Cliente ' + @IndexText, 'email' + @IndexText + '@test.com.br') | |
GO 2000 |
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 | |
DISTINCT | |
O.name, | |
O.type_desc | |
FROM | |
sys.sql_modules AS M | |
INNER JOIN | |
sys.objects AS O ON m.object_id = o.object_id | |
WHERE | |
M.definition LIKE '%Myterm%' | |
ORDER BY | |
2,1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment