Posts

Showing posts with the label SQL Server 2005

SQL - IsNullOrWhiteSpace Function

Just another SQL Code-snippet to check for NULL or whitespace value: -- ============================================= -- Author: John Wood -- Create date: 20151129 -- Description: Returns a boolean value -- ============================================= ALTER FUNCTION [Int].IsNullOrWhiteSpace ( -- Add the parameters for the function here @val sql_variant ) RETURNS bit AS BEGIN declare @ret bit if(SQL_VARIANT_PROPERTY(@val, 'BaseType') in ('varchar', 'nvarchar', 'char', 'nchar')) begin declare @char varchar = cast(@val as varchar) select @ret = iif(ltrim(rtrim(@char)) = '', 1, 0) end else begin -- Return the result of the function select @ret = iif( @val IS NULL, 1, 0 ) end return @ret END GO

SQL Agent Jobs - Non Maint Plan

While doing some development found a need to find non-Maintenance Plan Jobs for doing some reporting.  After couple minutes searching Google and some other sites, there is a huge lack of information or queries that effectively show how to obtain or tie system tables together to derive the literal SQL Agent Jobs. That being said, here is a little script i created that will query the system databases and produce a list of SQL Agent jobs. Code Snippet: 1: select * 2: from msdb.dbo.sysjobs as job 3: where job.job_id not in (select job_id from msdb.dbo.sysmaintplan_subplans)

Maintenance Plan history

I have been researching for the last couple of weeks a way to acquire a maintenance plan job history, success or failure. After alot of searching and finding that no one has or is not sharing the ability to do this, I decided to start hacking away at the MS SQL 2005/2008 core databases to find the relationship. After much digging, there are a total of 4 tables you need to have access to, whether through a proxy account of dbo schema account. Tables in question: - msdb..sysmaintplan_log - msdb..sysmaintplan_logdetail - msdb..sysmaintplan_subplans - msdb..sysjobs (optional: gives the SQL Agent Job name) SQL Script as i built it, but you will probably modify it to your needs: 1: SELECT 2: mpld.server_name, 3: j.name, 4: mpl.start_time, 5: mpl.end_time, 6: mpl.succeeded, 7: mpld.error_number, 8: mpld.error_message, 9: mpld.line1 + char(10) + char(13) + 10: mpld.line2 + char(10) + char(13) + 11: mpld.line3 + ch...