Posts

Showing posts from December, 2020

T-SQL for SSRS Data-Driven Subscriptions

 -- Find the Subscription ID based on the Description -- Subscription ID: 8BD6138A-9859-4F79-9394-41C50ED2FC22 (DEV) SELECT * FROM ReportServer.dbo.Subscriptions WHERE [Description] = 'Exception Policy Correction Plan Email'; -- Find the job created to run the data-driven subscription -- Look for the job step that contains the subscription ID -- job_id = '5A25474E-7014-4533-8D58-4C5971BF9776' SELECT * FROM msdb.dbo.sysjobsteps WHERE command LIKE '%8bd6138a-9859-4f79-9394-41c50ed2fc22%' /* Job Step command: exec [ReportServer].dbo.AddEvent  @EventType='TimedSubscription' , @EventData='8bd6138a-9859-4f79-9394-41c50ed2fc22' --<<< Subscription ID */

Simple JSON Examples

 DECLARE     @JSON    NVARCHAR(MAX) =         N'{"value":[{"AccountNumber":1003123456},{"AccountNumber":1004654321}]}'; SELECT * FROM OPENJSON(@JSON, '$.value')     WITH (         AccountNumber    BIGINT ); DECLARE     @JSON    NVARCHAR(MAX) =         N'[{"AccountNumber":1003123456},{"AccountNumber":1004654321}]'; SELECT * FROM OPENJSON(@JSON)     WITH (         AccountNumber    BIGINT );

How to Batch Updates A Few Thousand Rows at a Time

https://www.brentozar.com/archive/2020/12/how-to-batch-updates-a-few-thousand-rows-at-a-time/  

Multiple Options to Transpose Rows to Columns

https://www.sqlshack.com/multiple-options-to-transposing-rows-into-columns/  

Feature branches and pull requests with Git to manage conflicts

  https://www.red-gate.com/simple-talk/sql/database-devops-sql/feature-branches-and-pull-requests-with-git-to-manage-conflicts

RESTORE AdventureWorksLT2012 Database

RESTORE FILELISTONLY FROM DISK =  'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Backup\AdventureWorksLT2012.bak' RESTORE DATABASE AdventureWorksLT2012 FROM DISK =  'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Backup\AdventureWorksLT2012.bak' WITH MOVE 'AdventureWorksLT2008_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Data\AdventureWorksLT2012.mdf' , MOVE 'AdventureWorksLT2008_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Log\AdventureWorksLT2012.ldf'

Wide World Imports Sample Database

  Full Backup: WideWorldImporters-Standard.bak Backup Folder: C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL Check the data and log file paths: RESTORE FILELISTONLY FROM DISK =  'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Backup\WideWorldImporters-Standard.bak' Restore to my data and log file paths: RESTORE DATABASE WideWorldImporters FROM DISK =  'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Backup\WideWorldImporters-Standard.bak' WITH MOVE 'WWI_Primary' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Data\WideWorldImporters.mdf' , MOVE 'WWI_UserData' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Data\WideWorldImporters_UserData.ndf' , MOVE 'WWI_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019DEV\MSSQL\Log\WideWorldImporters.ldf'

Use OPENQUERY with a T-SQL query that has parameters

       DECLARE         @TSQL                                VARCHAR ( 8000 )     ,   @BRANCH_NUMBER                       VARCHAR ( 4 ) =              CONVERT ( VARCHAR ( 4 ), @P_BRANCH_NUMBER)     ,   @DATA_AS_OF                          CHAR ( 8 )      SET @TSQL =          'SELECT '      +     ' [Acctnum], [DataAs...

Pass a variable to a linked server query

https://docs.microsoft.com/en-us/troubleshoot/sql/admin/pass-variable-linked-server-query  

Getting Started with PowerShell File Properties and Methods

  https://www.mssqltips.com/sqlservertip/5878/getting-started-with-powershell-file-properties-and-methods/

PowerShell Module to Read Directory Contents and Store in a SQL Server Table

  https://www.mssqltips.com/sqlservertip/5802/powershell-module-to-read-directory-contents-and-store-in-a-sql-server-table/

Rename and Move a File with PowerShell

https://www.mssqltips.com/sqlservertip/3207/rename-and-move-a-file-with-powershell-in-a-sql-server-agent-job/   The code can easily be put into a SQL Agent job step.

Family Tree Stored Procedure

  http://bradsruminations.blogspot.com/2009/10/viva-la-famiglia.html

Recursion in SQL Explained Visually

https://medium.com/swlh/recursion-in-sql-explained-graphically-679f6a0f143b