UPDATE VS4TEmpTimeFill Set TTGMLeaveCode=''
GO

UPDATE VS4TEmpTimeFill Set TTGMLeaveCode='03',TTGMFlag2=786 where (TTGMLeaveCode='' or TTGMLeaveCode is null) AND TTGMDescription like '%ลาพักร้อน%'
GO

UPDATE VS4TEmpTimeFill Set TTGMLeaveCode='02',TTGMFlag2=787 where (TTGMLeaveCode='' or TTGMLeaveCode is null) AND TTGMDescription like '%ลากิจ%'
GO

UPDATE VS4TEmpTimeFill Set TTGMLeaveCode='01',TTGMFlag2=788 where (TTGMLeaveCode='' or TTGMLeaveCode is null) AND TTGMDescription like '%ลาป่วย%'
GO

UPDATE VS4TEmpTimeFill Set TTGMLeaveName=substring(TTGMDescription,1,CHARINDEX(' ',TTGMDescription,0)-1),TTGMFlag2=789 where (TTGMLeaveCode='' or TTGMLeaveCode is null) AND TTGMDescription like '%ลา%'
GO

UPDATE VS4TEmpTimeFill Set TTGMLeaveCode=(SELECT TOP 1 TElbTLvtCode FROM VS4TEmpLeaveMB WHERE VS4TEmpLeaveMB.TElbTEpaNo=VS4TEmpTimeFill.TTGMLeaveName AND VS4TEmpLeaveMB.TElbTEmpCode=VS4TEmpTimeFill.TTGMTEmpCode) where TTGMFlag2=789
GO