Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dasu
Posting Yak Master
104 Posts |
Posted - 2004-12-13 : 05:41:59
|
| IF EXISTS (SELECT name FROM sysobjects WHERE name = 'pr_cbs_upd_rlbk'AND type = 'P') DROP PROCEDURE pr_cbs_upd_rlbkGO/******************************************************************** PROCEDURE: pr_cbs_upd_rlbk* CREATED: Dasu Gairaboni 22-08-2004* LAST UPDATED ON: 22-08-2004** Variables in:* * * pintJobId - Job identifier** Variables out: pintStat - Stores stored procedures return value statement *** Description: For the given jobid this stored procedure rollbacks all the updateshave done on request response table .* DATE AUTHOR DESCRIPTION*-------------------------------------------------------------------*{modification description}********************************************************************/CREATE PROCEDURE pr_cbs_upd_rlbk @pintJobId INT,@pintStat INT OUTPUTAS/* VARIABLE DESCRIPTIONVARIABLE NAME TYPE OF VARIABLE DESCRIPTION @intUpdErr INT Update error code @intFail INT Stores failure status@intSuccess INT Stores success status@strErrMsg VARCHAR(255) Error information@strErrCD VARCHAR(30) Error code@strMdulNm VARCHAR(30) Name of the module @intJobid INT Stores jobid @intUpdJbobid INT Stores update jobid @strActNo VARCHAR(30) Stores account number@intAStatCd INT Stores audit table's status code@intDStatCd INT Stores request response tabel's status code@intRqstCd INT Stores request code @dtValDt DATETIME Stores request valuation date@intErrRsnId INT Stores error reason id */--Declaration of local variablesDECLARE@intUpdErr INT, @intFail INT , @intSuccess INT, @strErrMsg VARCHAR(255), @strErrCD VARCHAR(30), @strMdulNm VARCHAR(30),@intJobid INT,@intUpdJbobid INT,@strActNo VARCHAR(30),@intAStatCd INT,@intDStatCd INT,@intRqstCd INT,@dtValDt DATETIME,@intErrRsnId INT SET @intFail =DBO.FN_CBS_FAIL() --Generic constant for failureSET @intSuccess =DBO.FN_CBS_SUCCESS() --Generic constant for successSET @strMdulNm ='pr_cbs_upd_rlbk' --Stores module name -- Validation for jobidIF NOT EXISTS (SELECT upd_job_id FROM T_CBS_RQST_DTLS WHERE upd_job_id=@pintJobId)RETURN/* Update the jobstatus to invalid when the requested feed is trying to rollback. For example The outbound feed epi.req.txnpos.dts will populate the t_cbs_rqst_dtls table.After populating the records into t_cbs_rqst_dtls table if the feed fails to execute,the jobstatus has to rollback to previos status.But we do not have previos status in audit table so we make this status code as invalid.This piece of code will execute when job_id is equal to upd_job_id*/SELECT @intJobid=job_id,@intUpdJbobid=upd_job_id FROM T_CBS_RQST_DTLS WHERE job_id=@pintJobIdIF (@intJobid=@intUpdJbobid)BEGINUPDATE t_cbs_rqst_dtls SET stat_cd=DBO.FN_CBS_INVALIDATED(),upd_job_id=@pintJobIdWHERE upd_job_id=@pintJobIdAND job_id=upd_job_idIF (@@ERROR=0)--Logs information message about successful rollbackBEGINSET @pintStat=@intSuccess SET @strErrMsg ='Status code updated to '+CAST (DBO.FN_CBS_INVALIDATED() AS VARCHAR(30))SET @strErrCD=DBO.FN_CBS_INFO_UPD_RLBK()exec pr_cbs_log_error @pintJobId,@strMdulNm,@strErrCD,@strErrMsg RETURNENDELSE-- Error handling for update statement BEGIN SET @pintStat=@intFail SET @strErrMsg ='SQL ERROR NO IS '+ CAST (@intUpdErr AS VARCHAR(30))+'occured while updating status code to invalidate'SET @strErrCD=DBO.FN_CBS_UPD_ERR()exec pr_cbs_log_error @pintJobId,@strMdulNm,@strErrCD,@strErrMsgRETURNENDEND /* Update the jobstatus to its previous status when response feed is trying to rollback. For example The inbound feed epi.in.posapos.dts will update the t_cbs_rqst_dtls table.After updating the records into t_cbs_rqst_dtls table if feed fails to execute,jobstatus has to rollback to previos status by using audit table.This piece of code will execute if job_id not equals to upd_job_id */DECLARE curRqstDtls CURSOR LOCAL FORselect acct_no,val_dt,rqst_cd from t_cbs_rqst_Dtls where upd_job_id=@pintJobId-- Open cursor named curRqstDtlsOPEN curRqstDtls-- Search for first record set in curRqstDtlsFETCH NEXT FROM curRqstDtlsINTO @strActNo,@dtValDt,@intRqstCd -- Looping through all the records WHILE @@FETCH_STATUS=0BEGIN-- update stat_cd and upd_job_id and err_rsn_id to its previous status select @intDStatCd=stat_cd,@intJobid=job_id,@intErrRsnId=err_rsn_id from t_cbs_rqst_dtls_adt where acct_no=@strActNoand rqst_cd=@intRqstCdand sys_ts=(select max(sys_ts) from t_cbs_rqst_dtls_adt where acct_no=@strActNoand rqst_cd=@intRqstCd and job_id<>@pintJobId)update t_cbs_rqst_dtls set stat_cd=@intDStatCd,upd_job_id=@intJobid,err_rsn_id=@intErrRsnIdwhere upd_job_id=@pintJobIdand rqst_cd=@intRqstCdand acct_no=@strActNoand val_dt =@dtValDtSET @intUpdErr=@@ERRORIF(@@ERROR<>0)BEGIN SET @pintStat=@intFail SET @strErrMsg ='SQL ERROR NO IS '+ CAST (@intUpdErr AS VARCHAR(30))+'occured while updating status code 'SET @strErrCD=DBO.FN_CBS_UPD_ERR()exec pr_cbs_log_error @pintJobId,@strMdulNm,@strErrCD,@strErrMsgRETURNEND-- Fetch next record from curser FETCH NEXT FROM curRqstDtlsINTO @strActNo,@dtValDt,@intRqstCdendCLOSE curRqstDtls-- Close curRqstDtls cursorDEALLOCATE curRqstDtlsIF (@intUpdErr=0)BEGINSET @pintStat=@intSuccess SET @strErrMsg ='Successfully updating stat_cd to its previous status 'SET @strErrCD=DBO.FN_CBS_INFO_UPD_RLBK()exec pr_cbs_log_error @pintJobId,@strMdulNm,@strErrCD,@strErrMsg RETURNENDSome times this stored procedure taking 44 mnts for 20000 recordssomet times it is processing with in 3 mnts.why this difference suggest me proper solution with out cursor.please.dasu.g |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-12-13 : 05:54:26
|
| Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=43619 |
 |
|
|
|
|
|
|
|