Script SQL Server

Profile Monitor - Basic Analyze

  --// For Time / Duration In Trace Properties keep with only these options:   - RPC Completed (select all columns) - SQL BatchCompleted (select all columns)   >> Filter by: Duration Greater than > 5000 (5 secounds)     --// For CPU In Trace...

SQL Server Maintenance - Scripts and Good Practices

    Source: https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html       --// Validate last time that has been ran the reindex select name, Stats_date(id, indid) DataAtualizacao from sysindexes where id =...

Pesquisar por uma palavra em todas as tabelas e campos

  declare @idtabela int, @tabela varchar(255), @coluna varchar(255), @valorProcurado varchar(255)   --Coloque aqui a palavra ou expressão que deseja procurar set @valorProcurado = 'comercio'   drop table ##tmpFindString   create table ##tmpFindString...

Obter o 1º e último dias do mês anterior em SQL

    Como obter o 1º dia do mês anterior:   select dateadd(mm,-1,dateadd(dd,-day(getdate())+1,getdate()))   Como obter o último dia do mês anterior:   select dateadd(dd,-day(getdate()),getdate())   Neste exemplos usamos como data de referencia a...

Dynamically Generating Html/Excel/Word Document Files with SQL Server data using SSIS 2005

Como obter o 1º dia do mês anterior: select dateadd(mm,-1,dateadd(dd,-day(getdate())+1,getdate())) Como obter o último dia do mês anterior: select dateadd(dd,-day(getdate()),getdate()) Neste exemplos usamos como data de referencia a data actual, para obter em relação a outra data basta...

How to format datetime & date in Sql Server 2005

Execute the following Microsoft SQL Server T-SQL datetime and date formatting scripts in Management Studio Query Editor to demonstrate the multitude of temporal data formats available in SQL Server. First we start with the conversion options available for sql datetime formats with century (YYYY or...

SQL T-SQL Merge Command

This is a sample that we can use it: -- MERGE statement with the join conditions specified correctly. USE tempdb; GO BEGIN TRAN; MERGE Target AS T USING Source AS S ON (T.EmployeeID = S.EmployeeID) WHEN NOT MATCHED BY TARGET AND S.EmployeeName LIKE 'S%'     THEN INSERT(EmployeeID,...

MOD - Par numero - T-SQL

Exemplo de script:  SELECT ID FROM tabela WHERE (ID % 2) = 0 -- APARECE PAR  SELECT ID FROM tabela WHERE (ID % 2) <> 0 --APARECE  IMPAR  

Automatization Java x TSQL - Web browser

This script enable the resource to become the process to collect information by web sites and insert to the database: https://www.seleniumhq.org/docs/03_webdriver.jsp Recommended by Jeremy  

Function to get the address name

/*po box 21131 Lynnword ave32 Allen Street13 Miami Parade88 John StreetPO Box 346084 Seabrook Avenue128 Finlayson Ave25 Clinton Ave*/ALTER FUNCTION [dbo].[fnAddressName] (     @fullAddress NVARCHAR(MAX) ) RETURNS NVARCHAR(MAX) BEGIN   Declare...

<< 5 | 6 | 7 | 8 | 9 >>