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 |
STCCM
Starting Member
1 Post |
Posted - 2013-07-10 : 11:28:48
|
below I have a trigger that works however if there are 3 files in the location I am moving files from it moves all 3 and I only want it to move the oldest file of the 3. Then when the trigger is activated again I want it to again select only the oldest of the files in the said folder. Any help is much appreciated.CREATE TRIGGERTRG_RECEIVE_MOVEONTRANS FOR INSERT, UPDATE ASIF UPDATE(ITEM)beginupdate STATION set station.BinQuantity = 1FROMTRANSINNER JoiN INSERTEDONTRANS.TRANSNUMBER=INSERTED.TRANSNUMBERINNER JoiNSTATION ON TRANS.ITEM = STATION.ITEMWHEREINSERTED.TYPEDESCRIPTION = 'ISSUE' AND INSERTED.ITem LIKE 'RECEIVE%'DECLARE @file varchar(80), @cmd varchar(500);CREATE TABLE #temp(line varchar(100));INSERT #temp(line)EXEC sys.xp_cmdshell 'dir /B C:\OLD';SELECT TOP 1 @file=lineFROM #tempWHERE line IS NOT NULLORDER BY line;DROP TABLE #temp;PRINT @file;SET @cmd='MOVE /Y C:\OLD\'+@file+' C:\NEW\receive.csv'PRINT @cmdEXEC sys.xp_cmdshell @cmd; END |
|
|
|
|