USE [TEMPDB]
GO
/****** Object: StoredProcedure [dbo].[ChangeApprovalStatus] Script Date: 11/25/2008 09:55:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[ChangeApprovalStatus]
@strCompanyXML xml
AS
SET NOCOUNT ON
DECLARE @XMLDocPointer INT
DECLARE @RowCount INT
DECLARE @Error INT
DECLARE @Msg VARCHAR(100)
IF EXISTS ( SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[#tmpCompaniesXML]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].#tmpCompaniesXML
CREATE TABLE #tmpCompaniesXML(CompanyID VARCHAR(10))
IF @strCompanyXML IS NOT NULL
BEGIN
EXEC sp_xml_preparedocument @XMLDocPointer OUTPUT, @strCompanyXML
INSERT INTO #tmpCompaniesXML
SELECT * FROM OPENXML(@XMLDocPointer,'/root/company')
WITH (
[id] [varchar](10)
)
EXEC sp_xml_removedocument @XMLDocPointer
END
BEGIN TRANSACTION TRAN_UPD_TRKG
UPDATE T_Tracking
SET IsSFE=0,IsSynchronised=0
WHERE CompanyID IN (SELECT CompanyID FROM #tmpCompaniesXML)
SELECT @RowCount=@@ROWCOUNT,@Error=@@ERROR
IF @Error != 0 OR @Rowcount = 0
BEGIN
ROLLBACK TRANSACTION TRAN_UPD_TRKG
SET @Msg = 'Unable to update entry in T_Tracking'
RAISERROR(@Msg,16,1)
RETURN 0
END
SELECT @RowCount
COMMIT TRANSACTION TRAN_UPD_TRKG
IF EXISTS ( SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[#tmpCompaniesXML]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].#tmpCompaniesXML
RETURN 1
No comments:
Post a Comment