Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

get schedule description Expand / Collapse
Author
Message
Posted Thursday, April 1, 2010 7:22 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, January 18, 2013 5:32 AM
Points: 61, Visits: 171
Comments posted to this topic are about the item get schedule description
Post #895434
Posted Wednesday, April 14, 2010 10:29 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, December 4, 2014 10:11 AM
Points: 892, Visits: 1,560
Thanks for sharing Matthias. Different strokes for different folks so don't take the below as a criticism, just some of us have different coding styles so if you are like me and prefer for nested Conditions (i.e. the Case nesting) to be laid out in visual manner represenatative of thier nesting level and or use of Convert() iunstead of CAST() then the below is the re-formatted version of Mathias's code.

Again this is just a difference in style.

SELECT S.Schedule_ID,
S.Schedule_uID,
S.[name],
S.Enabled,
S.Freq_Type,
S.Freq_Interval,
S.Freq_Subday_Type,
S.Freq_Subday_Interval,
S.Freq_relative_Interval,
S.Freq_recurrence_Factor,
S.Active_Start_Date,
S.Active_End_Date,
S.Active_Start_Time,
S.Active_End_Time,
S.Date_Created,

Case WHEN S.Freq_Type = 0x1
THEN 'Once on ' + Convert( CHAR(10), Convert(DATETIME,Convert(VARCHAR,S.Active_Start_Date), 102) )
WHEN S.Freq_Type = 0x4 AND S.Freq_Interval > 0
THEN Case WHEN S.Freq_Interval > 1
THEN 'Every ' + Convert(VARCHAR,S.Freq_Interval) + ' days'
ELSE 'Every day'
END

WHEN S.Freq_Type = 0x8
THEN Case WHEN S.Freq_Recurrence_Factor = 1
THEN 'Weekly on '
WHEN S.Freq_Recurrence_Factor > 1
THEN 'Every ' + Convert(VARCHAR,S.Freq_Recurrence_Factor) + ' weeks on '
END

+ Left( Case WHEN S.Freq_Interval & 1 = 1
THEN 'Sunday, '
ELSE ''
END

+ Case WHEN S.Freq_Interval & 2 = 2 THEN 'Monday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 4 = 4 THEN 'Tuesday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 8 = 8 THEN 'Wednesday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 16 = 16 THEN 'Thursday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 32 = 32 THEN 'Friday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 64 = 64 THEN 'Saturday, ' ELSE '' END,

LEN ( Case WHEN S.Freq_Interval & 1 = 1 THEN 'Sunday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 2 = 2 THEN 'Monday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 4 = 4 THEN 'Tuesday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 8 = 8 THEN 'Wednesday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 16 = 16 THEN 'Thursday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 32 = 32 THEN 'Friday, ' ELSE '' END
+ Case WHEN S.Freq_Interval & 64 = 64 THEN 'Saturday, ' ELSE '' END
) - 1
)

WHEN S.Freq_Type = 0x10
THEN Case WHEN S.Freq_Recurrence_Factor = 1
THEN 'Monthly on the '
WHEN S.Freq_Recurrence_Factor > 1
THEN 'Every ' + Convert(VARCHAR,S.Freq_Recurrence_Factor) + ' months on the '
END
+ Convert(VARCHAR,S.Freq_Interval)
+ Case WHEN S.Freq_Interval IN(1, 21, 31)
THEN 'st'
WHEN S.Freq_Interval IN(2, 22)
THEN 'nd'
WHEN S.Freq_Interval IN(3, 23)
THEN 'rd'
ELSE 'th'
END

WHEN S.Freq_Type = 0x20
THEN Case WHEN S.Freq_Recurrence_Factor = 1
THEN 'Monthly on the '
WHEN S.Freq_Recurrence_Factor > 1
THEN 'Every ' + Convert(VARCHAR,S.Freq_Recurrence_Factor) + ' months on the '
END
+ Case S.Freq_relative_interval WHEN 0x01 THEN 'first '
WHEN 0x02 THEN 'second '
WHEN 0x04 THEN 'third '
WHEN 0x08 THEN 'fourth '
WHEN 0x10 THEN 'last '
END
+ Case S.Freq_Interval WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thursday'
WHEN 6 THEN 'Friday'
WHEN 7 THEN 'Saturday'
WHEN 8 THEN 'day'
WHEN 9 THEN 'week day'
WHEN 10 THEN 'weekend day'
END
WHEN S.Freq_Type = 0x40
THEN 'Automatically starts When SQLServerAgent starts.'
WHEN S.Freq_Type = 0x80
THEN 'Starts whenever the CPUs become idle'
ELSE ''
END

+ Case WHEN S.Freq_Subday_Type = 0x1 OR S.Freq_Type = 0x1
THEN ' at ' + Left(S.Active_Start_Time, 2) + ':' + Substring(S.Active_Start_Time, 3, 2) + ':' + Right(S.Active_Start_Time, 2)
WHEN S.Freq_Subday_Type IN(0x2, 0x4, 0x8)
THEN ' every '
+ Convert(VARCHAR,S.Freq_Subday_Interval)
+ Case freq_subday_type WHEN 0x2
THEN ' second'
WHEN 0x4
THEN ' minute'
WHEN 0x8
THEN ' hour'
END

+ Case WHEN S.Freq_Subday_Interval > 1
THEN 's'
ELSE ' '
END

ELSE ' '
END

+ Case WHEN S.Freq_Subday_Type IN(0x2, 0x4, 0x8)
THEN ' between ' + Left(S.Active_Start_Time, 2)
+ ':' + Substring(S.Active_Start_Time, 3, 2)
+ ':' + Right(S.Active_Start_Time, 2)
+ ' and ' + Left(S.Active_End_Time, 2)
+ ':' + Substring(S.Active_End_Time, 3, 2)
+ ':' + Right(S.Active_End_Time, 2)
ELSE ''
END
AS 'schedule'

FROM (SELECT SS.Schedule_ID,
SS.Schedule_uID,
SS.Originating_server_ID,
SS.[Name],
SS.Owner_sID,
SS.Enabled,
SS.Freq_Type,
SS.Freq_Interval,
SS.Freq_Subday_Type,
SS.Freq_Subday_Interval,
SS.Freq_relative_Interval,
SS.Freq_recurrence_Factor,
SS.Active_Start_Date,
SS.Active_End_Date,
Replicate('0', 6 - Len( Convert(VARCHAR,SS.Active_Start_Time))) + Convert(VARCHAR,SS.Active_Start_Time) AS 'Active_Start_Time',
Replicate('0', 6 - Len( Convert(VARCHAR,SS.Active_End_Time))) + Convert(VARCHAR,SS.Active_End_Time) AS 'Active_End_Time',
SS.Date_Created,
SS.Date_Modified,
SS.Version_number

FROM MSDB.dbo.SYSSCHEDULES SS ) AS S



Kindest Regards,

Just say No to Facebook!
Post #903337
Posted Thursday, October 3, 2013 11:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 8:51 PM
Points: 7,140, Visits: 12,763
Thanks for posting this code Matthias. Very helpful!

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1501288
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse