Sql Server

Read All SQL Server Log Files

You can use a script similar to the following to read through all SQL Server Log files: CREATE PROCEDURE SearchLogFiles (@LogType INT = 1, Filter NVARCHAR(MAX) = ”)ASBEGIN DECLARE @LogsTable

Using the STRING_AGG SQL Server 2017 Function

The STRING_AGG?SQL Server 2017 function performs grouped string concatenation. Here is an example: SELECT STRING_AGG(value, ‘ ‘) AS Result FROM (VALUES(‘Hannes’),(‘du’),(‘Preez’)) AS I(value); This returns: Hannes du Preez in the

Using sys.dm_db_index_physical_stats

Using dm_db_index_physical_stats?returns size and fragmentation information for the data and indexes of the specified table or view in SQL Server. USE master; GO — If Student.Name does not exist in

Transfer Data with JSON in SQL Server

You can transfer data with JSON in SQL Server. Based on an SQL query, you can output the results into JSON format. Here is a small example: DECLARE @JSONOutput NVARCHAR(MAX)

Compress and Decompress SQL Functions

Compress: Compresses input data and returns the binary data of type VARBINARY(MAX) Decompress: Decompresses compressed input binary data and returns the binary data of type VARBINARY(MAX) Here is small example

Using the STRING_SPLIT Function in SQL Server

SQL Server 2016 provides a way to split a string that is concatenated with a separator. For example: SELECT VALUE FROM STRING_SPLIT(“John|Mary|Dohe”, “|”) would return the values John, Mary and

Allow SQL Server to Silently Truncate Data

SQL Server usually presents an error on an attempt to insert more data into a field than it can hold. It typically throws an error message similar to the following: