Skip to content

Instantly share code, notes, and snippets.

View brunotdantas's full-sized avatar
🏠
Working from home

Bruno Dantas brunotdantas

🏠
Working from home
View GitHub Profile
@brunotdantas
brunotdantas / identity.sql
Created September 29, 2021 20:02
Add coluna id após criar a tabela, normalmente é util em situações que você precisa fazer um looping pela tabela criada
DROP TABLE IF EXISTS #VENDEDORES_ATIVOS;
SELECT Distinct
B.COD_VENDEDOR
,B.CODIGO_FILIAL
,A.CPF
INTO #VENDEDORES_ATIVOS
FROM #TMP_VENDEDORES_ATIVOS A
INNER JOIN TB_AUX_LNX_VENDEDOR B ON LTRIM(RTRIM(B.CPF)) = LTRIM(RTRIM(A.CPF))
WHERE
-- REGRAS CPFs VALIDOS
@brunotdantas
brunotdantas / getdate.bat
Last active September 27, 2021 18:30
get date bat file
rem Primeiro descubra o formato que o servidor está rodando o comando echo %date%
rem e aplique uma das funcionalidades abaixo
rem para PT-br
rem Transforma data em formato dd/mm/YYYY em YYYYmmDD, ou seja, 27/09/2021 em 20210927
rem a ténica abaixo é basicamente um substring
set year=%date:~6,4%
set month=%date:~3,2%
set day=%date:~0,2%
set pt_br_today=%year%%month%%day%
@brunotdantas
brunotdantas / PIVOT_exemplo.sql
Last active September 21, 2021 15:47
[T-SQL] - PIVOT tabela dinâmica SQL T-SQL exemplo #SQL SERVER
USE INTEGRADOR
GO
SELECT Dia, [Linx Venda] as Linx,[Integ. Venda] as Integrador,[L1 Venda OK] as Protheus,
[Linx Venda]-[Integ. Venda] as 'Linx - Integrador',
[Integ. Venda]-[L1 Venda OK] as 'Integrador - Protheus',
[Linx Venda]-[L1 Venda OK] as 'Linx - Protheus'
FROM (select Dia, Origem, QtdDoc from [VW_ConsultaIntegracao] where Dia > GETDATE()-3) as consulta
Pivot
(
@brunotdantas
brunotdantas / script.sql
Last active January 27, 2025 18:52
Hash SQL SERVER table row
-- https://stackoverflow.com/questions/11186183/hash-a-sql-row/54789730#54789730
drop table if exists #table1;
create table #table1 (
campo varchar(10)
,campo1 varchar(10)
)
drop table if exists #table2;
create table #table2 (
@brunotdantas
brunotdantas / server-info.sql
Created March 9, 2020 14:18
SQL INFORMATION SERVER SCRIPT
--https://docs.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-2017
-- 07/06/2019
SELECT
SERVERPROPERTY('BuildClrVersion') AS BuildClrVersion,
SERVERPROPERTY('Collation') AS Collation,
SERVERPROPERTY('CollationID') AS CollationID,
SERVERPROPERTY('ComparisonStyle') AS ComparisonStyle,
SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS ComputerNamePhysicalNetBIOS,
@brunotdantas
brunotdantas / test.js
Last active March 4, 2020 14:24
To test https://github.com/typicode/lowdb #Json #database #local #storage #localstorage #localdb
'use strict'
/* steps to use this test file:
1- install package lowdb : npm install lowdb
2- create a file empty data.json
3- manipulate the variable option to test the scenarios you want
*/
@brunotdantas
brunotdantas / script-bkp.sql
Last active March 3, 2020 18:14
T-SQL script to backup local database
-- #tags #sql #backup #bkp #sqlcmd #scheduler #windows
-- run this via batch
-- sqlcmd -S localhost -U [username] -P [password] -d master -Q "exec sp_BackupDatabases '[databaseName]','[typeOfBackup]', '[directoryToSaveData]'"
-- https://support.microsoft.com/en-us/help/2019698/how-to-schedule-and-automate-backups-of-sql-server-databases-in-sql-se
-- =============================================
-- Author: Microsoft
-- Create date: 2010-02-06
-- Description: Backup Databases for SQLExpress
@brunotdantas
brunotdantas / query-api-ajax
Created February 20, 2020 23:12
Ajax example with promises
// Use this solution when we need to do an action when the request is finished
var myPromise = function(){
return new Promise(function(resolve,reject){
var xhr = new XMLHttpRequest();
xhr.open('GET','https://api.github.com/users/brunotdantas');
xhr.send(null); // if you have any parameters to complement the request
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
--https://stackoverflow.com/questions/662383/better-techniques-for-trimming-leading-zeros-in-sql-server/662437#662437
SELECT SUBSTRING(IDCLIENTE, PATINDEX('%[^0]%', IDCLIENTE+'.'), LEN(IDCLIENTE)) ,* FROM TB_IN_SAP_CUSTOMER WHERE CNPJ IN ( 'zzzzzz')
/*
Solução pro erro:
Mensagem 1755, Nível 16, Estado 0, Linha 22
Não podem ser criados padrões em colunas de carimbo de data/hora do tipo de dados. Tabela 'STG_MSAF_SALES_HEADER', coluna 'created_timestamp'.
Mensagem 1750, Nível 16, Estado 0, Linha 22
Não foi possível criar a restrição ou o índice. Consulte os erros anteriores.
quando feito:
ALTER TABLE STG_MSAF_SALES_HEADER ADD created_timestamp timestamp default getdate()