Posts

Failed Subscription Alerting T-SQL Script

USE ReportServer GO DECLARE @count INT SELECT     Cat.[Name],     Rep.[ScheduleId],     Own.UserName,     ISNULL(REPLACE(Sub.[Description],'send e-mail to ',''),' ') AS Recipients,     Sub.[LastStatus],     Cat.[Path],     Sub.[LastRunTime] INTO     #tFailedSubs FROM     dbo.[Subscriptions] Sub with (NOLOCK) INNER JOIN     dbo.[Catalog] Cat with (NOLOCK) on Sub.[Report_OID] = Cat.[ItemID] INNER JOIN     dbo.[ReportSchedule] Rep with (NOLOCK) ON (cat.[ItemID] = Rep.[ReportID] and Sub.[SubscriptionID] =Rep.[SubscriptionID]) INNER JOIN     dbo.[Users] Own with (NOLOCK) on Sub.[OwnerID] = Own.[UserID] WHERE Sub.[LastStatus] NOT LIKE '%was written%' --File Share subscription AND Sub.[LastStatus] NOT LIKE '%pending%' --Subscription in progress. No result yet AND Sub.[LastStatus] NOT LIKE '%mail sent%' --Mail sent successfully. AND Sub...

Best practice for SSIS

Ø   Avoid copying from remote server window to local machine, SSIS package can get corrupted. Copy the SSIS Package from shared path location to local machine.   Ø   Maintain documentation and keep it updated for Column Mapping including Data Length and Data Type for Source and Destination   Ø   Use of handshaking table between Upstream-> Datamart (MS BI) -> Downstream applications   Ø   Use of SEND MAIL NOTIFICATION TASK in SSIS Package to inform about the Data loading/ cube processing start and finish to all concerned parties   Ø   Optimize the Query/ SP run time before placing/calling it in SSIS Package to improve performance   Ø   Use of intermediary table in case of huge data loads will ensure faster load and unaffected performance of target table   Ø   Use Sequence Container with TransactionOption property set as required in order to rollback a series of task if one task fails. A...

Best practises for SSRS

Ø   Optimize the query to avoid unnecessary burden on the database. Avoid the use of "SELECT *" statement and specify only the columns that are required in report. Ø   Do not use Report Parameters to filter the report data unless you are using Snapshot reports. Use Query parameters instead of Report parameters as Query parameters filters data while extracting it from database server to Report Server. On the other hand, when Report parameters are implemented, report is re-executed again based on report parameters/filters and the report server filters data again based on Report parameters. Ø   Prefer to use Custom Assemblies rather than Embedded Code in case the same Custom Function (Embedded Code) needs to be referenced in multiple reports.  

SQL Server Version History

Image
SQL Server Version History Information  

SQL Server Running Jobs Time Elapsed status

CREATE TABLE #enum_job   (     Job_ID uniqueidentifier,     Last_Run_Date          INT,     Last_Run_Time          INT,     Next_Run_Date          INT,     Next_Run_Time          INT,     Next_Run_Schedule_ID   INT,     Requested_To_Run       INT,     Request_Source         INT,     Request_Source_ID      VARCHAR(100),     Running                INT,     Current_Step           INT,     Current_Retry_Attempt INT,...

Script to backup all SQL Server databases

DECLARE @name VARCHAR(50) -- database name   DECLARE @path VARCHAR(256) -- path for backup files   DECLARE @fileName VARCHAR(256) -- filename for backup   DECLARE @fileDate VARCHAR(20) -- used for file name -- specify database backup directory SET @path = 'C:\Backup\' -- specify filename format SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) DECLARE db_cursor CURSOR READ_ONLY FOR   SELECT name FROM master.dbo.sysdatabases WHERE name NOT IN ('master','model','msdb','tempdb')   -- exclude these databases OPEN db_cursor    FETCH NEXT FROM db_cursor INTO @name    WHILE @@FETCH_STATUS = 0    BEGIN       SET @fileName = @path + @name + '_' + @fileDate + '.BAK'      BACKUP DATABASE @name TO DISK = @fileName      FETCH NEXT FROM db_cursor INTO @name    END    CLOSE db_cursor    DEALLOCATE db_cur...

How to check status of SQL jobs through query

Use msdb GO SELECT distinct j.Name as "Job Name", --j.job_id, CASE j.enabled WHEN 1 THEN 'Enable' WHEN 0 THEN 'Disable' END as "Job Status", jh.run_date as [Last_Run_Date(YY-MM-DD)], CASE jh.run_status WHEN 0 THEN 'Failed' WHEN 1 THEN 'Successful' WHEN 2 THEN 'Retry' WHEN 3 THEN 'Cancelled' WHEN 4 THEN 'In Progress' END as Job_Execution_Status FROM sysJobHistory jh, sysJobs j WHERE j.job_id = jh.job_id and jh.run_date =   (select max(hi.run_date) FROM sysJobHistory hi WHERE jh.job_id = hi.job_id )-- to get latest date