Query to find the SSIS package run schedule - sql-server

I have created a SQL Server 08 database maintenance plan using the Wizard.
The job shows in the msdb.sysjobs table but it doesn't show the schedule in the msdb.sysjobschedules table because the Wizard created it as an SSIS package. - fine
Then I go to the msdb.sysssispackages and I can see the package there but nothing about the next scheduled run date.
My question is if it is possible to create a query to get the job schedule for that type of job. Something as simple as next_run_date like in the sysjobschedules table.
Thank you.

This works for me.
SELECT *
FROM msdb.dbo.sysmaintplan_plans p
INNER JOIN msdb.dbo.sysmaintplan_subplans sp
ON p.id = sp.plan_id
LEFT OUTER JOIN msdb.dbo.sysjobschedules j
ON j.schedule_id = sp.schedule_id

Related

How to link Report Server Subscription SQL Agent Job name to the name of the report it is running

On my Report Server database all my users' Report Subscriptions are saved as SQL Agent Jobs, as is normal.
If I connect to the Report Server DB and list out the SQL Agent jobs I see a huge list of jobs named as random strings of characters, eg:
000D5787-8802-4CB1-9784-8897C596003F
By a process of trial and error, I have figured out that particular Agent job relates to my "Daily Sales" report, and I'm able to view the Job History, add SQL commands to the code that the Subscription runs, etc.
However, I have hundreds of user reports. I need to be able to tie back the name of the report to the name of the SQL Agent job somehow. Either by getting Report Server to name its subscription jobs more helpfully, or by having some kind of lookup table that I can refer to when I'm scrolling down the list of Jobs.
Any ideas? I've tried looking in the "Subscriptions" table of ReportServer, it does have some ID numbers which look similar, but none of them match the Job names.
Run the following code .. it should give you a list of all the reports with a subscription and what the job names are:
SELECT distinct
sj.[name] AS [Job Name],
rs.SubscriptionID,
c.[Name] AS [Report Name],
c.[Path]
FROM msdb..sysjobs AS sj
INNER JOIN ReportServer..ReportSchedule AS rs
ON sj.[name] = CAST(rs.ScheduleID AS NVARCHAR(128))
INNER JOIN ReportServer..Subscriptions AS su
ON rs.SubscriptionID = su.SubscriptionID
INNER JOIN ReportServer..[Catalog] c
ON su.Report_OID = c.ItemID
you can then trigger the jobs by running the following command:
USE [msdb]
EXEC sp_start_job #job_name = '[Job Name] from above query'

SSIS: can not run an sql task to update table

I'm new to SSIS and SQL Server and what I'm trying to do is to update a table that I have in my database. But it doesn't work with "Execute SQL Task".
Here is what I'm trying to do:
Create 2 tables if they do not exists (one the final table and the other to store the data that already exists in the database)
get the data from excel file and my database
then I use sort and merge join + derived column + conditional split to get the newest data into the final table and the data that already exists in the database in another table
afterwards, I'm trying to update the table but here is the problem
Here is the SQL query I use:
update
A
set
A.[nom technicien] = B.[nom technicien],
A.[nb intervention] = B.[nb intervention],
A.[tel] = B.[tel],
A.[mail] = B.[mail],
A.[adresse] = B.[adresse],
A.[id] = B.[id]
from
fichetech A
inner join fichetechstaged B on
A.[id] = B.[id];
I searched on the internet and haven't found anything that would help me.
Here is a screenshot of the error I get:
Well i figure it out by myself xD. It took me a while but i did it.
So, what worked for me is: in SQL EXECUTE TASK-> SQL STATEMENT -> BypassPrepare -> False and it worked perfectly.
IDK why it work. If someone can explain it would be great.
Thanks everyone for the help.

Executing SSRS Reports From SSIS

I need to execute a SSRS reports from SSIS on periodic schedule.
Saw a solution here :
https://www.mssqltips.com/sqlservertip/3475/execute-a-sql-server-reporting-services-report-from-integration-services-package/
But is there any other option in SSIS without using Script Task ? I don't quite understand the script and concern there could be some support issue for me.
Database : SQL Server 2008R2 Standard Edition
Any ideas ? Thanks very much ...
SSIS controlling the running of an SSRS in SQL Agent.
This assumes that the SSIS job will have updated a control record or written some other identifiable record to a database.
1. Create a subscription for the report.
2. Run this SQL to get the GUID of the report
SELECT c.Name AS ReportName
, rs.ScheduleID AS JOB_NAME
, s.[Description]
, s.LastStatus
, s.LastRunTime
FROM
ReportServer..[Catalog] c
JOIN ReportServer..Subscriptions s ON c.ItemID = s.Report_OID
JOIN ReportServer..ReportSchedule rs ON c.ItemID = rs.ReportID
AND rs.SubscriptionID = s.SubscriptionID<br>
3. Create a SQL Agent job.
a. Step 1. A SQL statement to look for data in a table containing a flagged record where the Advanced setting is "on failure end job reporting success"
IF NOT exists ( select top 1 * from mytable where mykey = 'x'
and mycondition = 'y') RAISERROR ('No Records Found',16,1)
b. Step 2
USE msdb
EXEC sp_start_job #job_name = ‘1X2C91X5-8B86-4CDA-9G1B-112C4F6E450A'<br>
Replacing the GUID with the one returned from your GUID query.
One thing to note though ... once the report subscription has been executed then as far as SQL Agent is concerned then that step is complete, even though the report has not necessarily finished running. I once had a clean up job after the Exec step which effectively deleted some of my data before the report reached it!
You can create a subscription for the report that is never scheduled to run.
If you have the Subscription ID, you can fire the report subscription using a simple SQL Task in SSIS.
You can get the Subscription ID from the Report Server database. It is in the Subscriptions table.
Use this query to help locate the subscription:
SELECT Catalog.Path
,Catalog.Name
,SubscriptionID
,Subscriptions.Description
FROM Catalog
INNER JOIN Subscriptions
ON Catalog.ItemID = Subscriptions.Report_OID
In SSIS, you can use this statement, inside of a SQL Task, to fire the subscription:
EXEC reportserver.dbo.AddEvent #EventType='TimedSubscription',#EventData= [Your Subscription ID]
Hope this helps.

How to monitor an SQL Server Agent Job that runs after being triggered

I'm running SQL Server 2008 and I have 3 agent jobs set up to run one after the other because the success of the second depends on the first, etc.
Every other job I have is independent and I monitor using a script that incorporates MSDB..sysjobhistory run_status field, among others.
I want to know if there is a way to specifically find all jobs that never started for a specific day. I know that I can think of the problem the other way and say job 2 couldn't possibly run if job 1 failed; however, I'm looking for a more general purpose solution so in case I need to create other jobs that are linked similarly I won't have to hard code more logic into my nightly report.
Any suggestions are welcome!
The MSDB..sysjobservers table holds a single record for every agent job in your server, and includes the field last_run_date which makes it easy to tell which jobs haven't run in the last 24 hours. My query looks something like this
SELECT A.name AS [Name]
,##servername AS [Server]
,'Yes' AS [Critical]
FROM MSDB.dbo.sysjobs A
INNER JOIN MSDB.dbo.sysjobservers B ON A.job_id = B.job_id
WHERE A.name LIKE '2%SPRING%'
AND DATEDIFF(DAY, CONVERT(DATETIME, CONVERT(CHAR(8),B.last_run_date)), GETDATE( )) > 1)

SQL Server Management Studio - history of commands run

I have previously altered a table, added a column and modify a stored procedure.
I do not remember exactly which table and which stored procedure,
is there some log in sql management studio about what changes were done in a particular DB?
I have tried what is described here How to see query history in SQL Server Management Studio but i have not found the changes made to the DB
There's a few ways that you can get this information. Firstly you could try the standard reports --> Schema Changes History.
The information for this comes from:
SELECT cat.name AS Category
, b.name AS EventCaptured
, c.name AS ColumnCaptured
FROM fn_trace_geteventinfo(1) AS a
INNER JOIN sys.trace_events AS b
ON a.eventid = b.trace_event_id
INNER JOIN sys.trace_columns AS c
ON a.columnid = c.trace_column_id
INNER JOIN sys.trace_categories AS cat
ON b.category_id = cat.category_id
ORDER BY Category, EventCaptured, ColumnCaptured
Alternatively, query sys.traces to find the location of the default trace and feed this into fn_trace_gettable as per below.
SELECT *
FROM fn_trace_gettable
('C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\log.trc', default)
You can use Security\Server Audit Specification and enable DATABASE_OBJECT_CHANGE_GROUP audit on your database.
Use following reference in order to use SQL Server server audit.
CREATE SERVER AUDIT SPECIFICATION (Transact-SQL)
Create a Server Audit and Server Audit Specification
You can use the modify_date column in sys.objects table
SELECT *
FROM SYS.OBJECTS
WHERE Modify_Date BETWEEN <date_of_modification> AND <date_of_modification> + 1
and then you can try to narrow it down.
You can be even more specific and run the query for just tables and stored procedures.
SELECT *
FROM SYS.objects
WHERE TYPE IN ('IT', 'S', 'U', 'P', 'PC', 'X')
AND modify_date BETWEEN '10-Jun-2014' AND '11-Jun-2014'
I develop SSMSBoost add-in for SSMS and we have "Executed Query history" there. All actions are logged with timestamp, connection information and execution result. This will certainly only work, if you do all changes from SSMS with SSMSBoost installed. If someone will perform changes from other machine you will not see them, until he uses SSMSBoost as well and you share execution history.

Resources