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
-- VARCHAR TO Base64 | |
IF OBJECT_ID (N'[dbo].[uFnStringToBase64]', N'FN') IS NOT NULL | |
DROP FUNCTION uFnStringToBase64; | |
GO | |
CREATE FUNCTION [dbo].[uFnStringToBase64] | |
( | |
@InputString VARCHAR(MAX) | |
) | |
RETURNS VARCHAR(MAX) | |
AS |
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 DATE, @endDate DATE, @batchSize INT | |
SET @startDate = '2022-05-01' | |
SET @endDate = '2022-05-31' | |
SET @batchSize=4 | |
;WITH dates AS ( | |
SELECT @startDate as batchStartDate, DATEADD(DAY, @batchSize, @startDate) batchEndDate | |
UNION ALL | |
SELECT DATEADD(DAY, 1, batchEndDate) batchStartDate, DATEADD(DAY, 1 + @batchSize, batchEndDate) batchEndDate |
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 | |
LEN(col) - LEN(REPLACE(col, ',', '')) count_commas | |
FROM table |
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
$rc = [Reflection.Assembly]::LoadFile("path to sanco\sapnco.dll") | |
$rc = [Reflection.Assembly]::LoadFile("path to sanco\sapnco_utils.dll") | |
$Version = [SAP.Middleware.Connector.SAPConnectorInfo]::get_Version() | |
$PatchLevel = [SAP.Middleware.Connector.SAPConnectorInfo]::get_KernelPatchLevel() | |
$SAPRelease = [SAP.Middleware.Connector.SAPConnectorInfo]::get_SAPRelease() | |
Write-Host "`r`nNCo verion:" $Version | |
Write-Host "Patch Level:" $PatchLevel | |
Write-Host "SAP Release:" $SAPRelease |
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
IF EXISTS ( SELECT * | |
FROM sys.dm_xe_database_sessions AS dxds | |
WHERE dxds.name = 'system_health') | |
DROP EVENT SESSION system_health ON DATABASE; | |
GO | |
CREATE EVENT SESSION system_health | |
ON DATABASE | |
ADD EVENT sqlserver.error_reported | |
(ACTION (sqlserver.session_id, | |
sqlserver.database_id, |
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('string' as varbinary(max)) FOR XML PATH(''), BINARY BASE64 | |
SELECT CAST( CAST( 'c3RyaW5n' as XML ).value('.','varbinary(max)') AS varchar(max) ) |
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
Get-FileHash -Path FileName -Algorithm SHA256 |
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
-- Replace SCHEMA and FILTER with your schema and table filter | |
-- Remove last UNION ALL from result | |
SELECT | |
CONCAT('SELECT ''', TABLE_NAME, ''' [TABLE_NAME], COUNT(*) [ROWS] FROM ', QUOTENAME(TABLE_SCHEMA), '.', QUOTENAME(TABLE_NAME),' UNION ALL') | |
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='SCHEMA' AND TABLE_NAME LIKE 'FILTER' |
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
# Count files in current dir and all subdirectories | |
(Get-ChildItem *.jpg -Recurse -File | Measure-Object).Count | |
# Measure size of files in current directory and all subdirectories (in Gb) | |
(Get-ChildItem *.jpg -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1Gb | |
# Get 100 random jpg files and exclude FOLDER (you have to provide CountOfFiles) | |
Get-ChildItem -Exclude FOLDER | Get-ChildItem -Recurse -Filter *.jpg -File | Get-Random -Count CountOfFiles | Select-Object -First 100 | |
# Same as above but copies selected files to DESTINATION_FOLDER |
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
ALTER TABLE DatabaseName.SchemaName.TableName SET (SYSTEM_VERSIONING = OFF) | |
EXEC sp_rename 'DatabaseName.SchemaName.TableName.ColumnName', 'NewColumnName', 'COLUMN'; | |
ALTER TABLE DatabaseName.SchemaName.TableName SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = SchemaName.HistoryTableName)) |
NewerOlder