Gerard's codebase

This is a personal repository of code snippets and information.

Over the years I have generated lots of little sub programs and stored away acres of useful code snippets. The problem is always to locate them.

Even more time wasting is forgetting how to do simple things when you havnt developed in an environment for a few years (or even a few months)

My new years resolution is to start putting them up in a common place as I produce them. (thanks google)

They are handy for me and, with a bit of a clean up and documentation, they might be handy for others if they wander in here.

Gerard 2008

Tuesday, June 4, 2019

How long a SQL Agent job takes to run





USE msdb
select
j.job_id
,j.name as job_name
, s.step_name
, s.step_id
-- , s.command
,dbo.agent_datetime(run_date, 0) as step_start_date
,dbo.agent_datetime(run_date, run_time) as step_start_date_time
--,h.instance_id
,h.run_duration
,run_duration/10000 as run_duration_hours_only --hours
,run_duration/100%100 as run_duration_minutes_only --minutes
,run_duration%100 as run_duration_second --seconds
,(run_duration/10000 * 60 * 60) + -- hours as seconds
(run_duration/100%100 * 60) + --minutes as seconds
(run_duration%100 ) as run_duration_total_seconds --seconds
-- , h.*
from msdb.dbo.sysjobs j inner join
msdb.dbo.sysjobsteps s on j.job_id = s.job_id inner join
msdb.dbo.sysjobhistory h on s.job_id = h.job_id and s.step_id = h.step_id
where
1=1
and j.name like  'My Job Name'
--order by h.instance_id desc

Tuesday, January 15, 2019

Create a "LIKE " type filter for a string parameter in SSRS report


You can create a simple user defined filter parameter by applying a filter to the recordset and writing a bit of VB code

The VB code is as follows:

Public Function fnLike(ByVal val as string, ByVal Filter as string) AS Boolean

val = lcase(val)
Filter = lcase(Filter)

If len(trim(filter)) = 0 then
    Return True
End If

If val.contains(filter) Then
    Return True
Else
    Return False
End If
End Function


To implement simply put the following in to the Filter Expression for the recordset

=code.fnLike(Fields!EMPLOYEE_NAME.Value, Parameters!PractitionerName.Value)

For the other parameters for the filter set
  • Type - Boolean
  • Operator "="
  • Value - True