UPDATE VS4TChequeRec Set TCHRPassTGLTNo=(SELECT TOP 1 TGLTNO FROM VS4TGLTrans WHERE VS4TGLTrans.TGLTRefNo=VS4TChequeRec.TCHRNo AND VS4TGLTrans.TGLTCancelStatus=0 AND VS4TGLTrans.TGLTInputSource='RCQ' ORDER BY TGLTDate DESC,TGLTNo DESC) 
WHERE TCHRChqStatus=0 AND (TCHRPassTGLTNo='' OR TCHRPassTGLTNo is null)
GO
UPDATE VS4TChequeRec Set TCHRPassTGLTNo='' WHERE TCHRPassTGLTNo is null
GO
UPDATE VS4TChequeRec Set TCHRTGLTNo=(SELECT TOP 1 TGLTNO FROM VS4TGLTrans WHERE VS4TGLTrans.TGLTRefNo=VS4TChequeRec.TCHRNo AND VS4TGLTrans.TGLTCancelStatus=0 AND VS4TGLTrans.TGLTInputSource='XRCQ' ORDER BY TGLTDate DESC,TGLTNo DESC) 
WHERE TCHRChqStatus=0 AND (TCHRTGLTNo='' OR TCHRTGLTNo is null)
GO
UPDATE VS4TChequeRec Set TCHRTGLTNo='' WHERE TCHRTGLTNo is null
GO
UPDATE VS4TChequeRec Set TCHRChqStatus=2 WHERE TCHRChqStatus=0 AND TCHRPassTGLTNo<>''
GO
UPDATE VS4TChequeRec Set TCHRChqStatus=3 WHERE TCHRChqStatus=0 AND TCHRTGLTNo<>''
GO
UPDATE VS4TChequeRec Set TCHRChqStatus=0 WHERE TCHRChqStatus is null
GO

