Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Always updating the Phase to O and not inserting into a table

Status
Not open for further replies.

comsci

Programmer
May 15, 2011
1
ZA
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER TRIGGER UC_IBTOut_QtyTrig
ON UC_IBTOut
FOR INSERT, UPDATE
AS
DECLARE @OriginID uniqueidentifier
DECLARE @ErrorText VaRcHaR(60)
SELECT TOP 1 @OriginID = BranchID from UC_InStoreSetup
DECLARE @IBTSetupID uniqueidentifier
--EXEC UC_SysMembership_FindSetup @OriginID, 'UC_IBTSetup', @IBTSetupID OUTPUT
DECLARE @AutoReceive bit
DECLARE @AffectInTransitOf char(1) -- AITO
SELECT @AutoReceive = MustAutoReceive
, @AffectInTransitOf = 'R' -- (R)eceiving (verus (S)ending)
FROM UC_IBTSetup
--WHERE @IBTSetupID --Old Structure
WHERE IBTSetupID = 'SETTINGS'


/*The update must ignore the storeforward table and always update the phase to 'O'. The section for the count in the following line should also be part of the update UC_IBTOutDetail D. The header is uc_ibtout and the detail line is UC_IBTOutDetail.*/

-- Store Forward
IF UPDATE(RowStatus) AND NOT UPDATE(Name) GOTO Leave
--Remove Old StoreForward Records
DELETE FROM UC_StoreForward WHERE RowGUID IN (SELECT RowGUID FROM INSERTED)


--Insert Record --select * from UC_StoreForward
INSERT UC_StoreForward
( RowGUID
, OriginID
, TableName
, TableNameDetail
, TransactionID
, StoreForwardHeadID
, IsForwarded
, IsVerified
, NoteID
, RowStatus
, CrDateTime
, CrProg
, CrUser
, LmDateTime
, LmProg
, LmUser
)
SELECT I.RowGUID
, I.OriginID
, 'UC_IBTOut'
, 'UC_IBTOutDetail'
, I.IBTOutID
, '{25FEDBD8-C410-4241-9AB3-BC2923847598}'
, 0
, 0
, NULL
, 2048
, GetDate()
, 'UC_IBTOut_QtyTrig'
, 'DB'
, GetDate()
, 'UC_IBTOut_QtyTrig'
, 'DB'
FROM INSERTED I
LEFT JOIN UC_IBTOutDetail D ON I.RowGUID = D.IBTOutID
AND D.RowStatus & 144 = 0
WHERE I.OriginID != @OriginID
AND I.TotalLineCnt IS NOT NULL
AND I.Rowstatus & 144 = 0 --SPNVF 12/09/2007
GROUP BY I.TotalLineCnt
, I.RowGUID
, I.OriginID
, I.IBTOutID
HAVING I.TotalLineCnt != COUNT(D.IBTOutDetailID)
--Update Phase for Correct Transactions

UPDATE A
SET Phase = CASE WHEN ISNULL(D.Phase, 'O') = 'C' THEN D.Phase ELSE 'O' END --Added by DW --Phase 'O' --Open for Receiving
FROM UC_IBTOut A
JOIN INSERTED I
ON I.RowGUID = A.RowGUID
LEFT JOIN DELETED D
ON D.RowGUID = A.RowGUID
AND D.RowGUID = I.RowGUID
LEFT JOIN UC_StoreForward F
ON I.RowGUID = F.RowGUID
WHERE F.RowGUID IS NULL
OR F.IsForwarded = 1
Leave:
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top