Sie sind auf Seite 1von 3

USE [csdd761a]

GO
/****** Object: StoredProcedure [interim].[usp_write_log_data_validation]
Script Date: 18/11/2016 16:34:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [interim].[usp_write_log_data_validation]


(
@db_load_job_id INT
,@master_job_id INT
,@package_name TYP_SHORTDESC = NULL
,@load_start_time DATETIME
,@task_name TYP_SHORTDESC = NULL
,@message_type_key CHAR(1)
,@log_message TYP_LOGMESSAGE
)

AS

/
***********************************************************************************
*************************************************
* Name : [usp_write_log]
* Purpose : This procedure is for creating detailed log entries.
* Method :
* Input Params :
* @db_load_job_id : The Log ID for which the
master log entry is being created.
* @package_name : The Package Name for
which the detailed log entry is being created.
* @task_name : The Task Name for which
the detailed log entry is being created.
* @message_type_key : A single characted denoting
the type of message.
* 'C' - Completion
* 'E' - Error
* @log_message : The messaged to be
logged.
*
*
* Versions : No Author Date Comments
* : -- ------ ---- --------
* : 0 Thass\Sridharan 13-Nov-2013
Original version.
***********************************************************************************
*************************************************/

BEGIN
DECLARE @step SMALLINT -- Identifies the
step in the stored procedure.
DECLARE @msg VARCHAR(2000) -- The message that
is logged.
DECLARE @err_desc VARCHAR(1000) -- The system generated
error message which is logged.
DECLARE @err_code INT -- The system
generated error number which is logged.
DECLARE @err_state INT -- The system
generated error state which is logged.

BEGIN TRY
-- Initialise variables
SET @msg = ''
SET @err_desc = NULL
SET @step = 0

-- Check parameter information and provide details on the procedure if


it is being called from the command line.
SET @msg = 'Checking parameter information'
SET @step = @step + 1
IF(@db_load_job_id IS NULL OR @message_type_key IS NULL OR @log_message
IS NULL)
BEGIN
SET @msg = @msg + 'This procedure has the following Mandatory
parameters. Ensure all parameters have a value.'
+ ''
+ ' @db_load_job_log_id -- INT
The Log ID for which the detailed log entry is being created.'
+ ' @message_type_key -- CHAR(1)
A single characted denoting the type of message. C - Completion E - Error'
+ ' @log_message --
TYP_LOGMESSAGE The messaged to be logged.'

RAISERROR(@msg, 16, 1)

RETURN 0
END

--Create a new Detail Log entry

SET @msg = 'Creating the Detail Log Entry'


SET @step = @step + 1

INSERT INTO [interim].[db_data_validation_job_log_temp]


(
[db_master_job_id]
,[db_load_job_id]
,[package_name]
,[job_start_date]
,[task_name]
,[message_type_key]
,[log_message]
,[log_start_date]
,[error_code]
,[error_message]
)
SELECT
@master_job_id
,@db_load_job_id
,@package_name
,@load_start_time
,@task_name
,@message_type_key
,@log_message
,GETDATE()
,@err_code
,@err_desc

END TRY
BEGIN CATCH
SET @msg = 'Error while performing: ' + @Msg + ' at Step Number : ' +
CAST(@step AS VARCHAR(2))
SET @err_desc = ERROR_MESSAGE()
SET @err_code = ERROR_SEVERITY()
SET @err_state = ERROR_STATE()
RAISERROR(@msg,@err_code,@err_state)
END CATCH
END

Das könnte Ihnen auch gefallen