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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 stop a xp_cmdshell after 1st pass

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 TRIGGER
TRG_RECEIVE_MOVE
ON
TRANS FOR INSERT, UPDATE AS
IF UPDATE(ITEM)
begin
update STATION set station.BinQuantity = 1
FROM
TRANS
INNER JoiN INSERTED
ON
TRANS.TRANSNUMBER=INSERTED.TRANSNUMBER
INNER JoiN
STATION ON TRANS.ITEM = STATION.ITEM
WHERE
INSERTED.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=line
FROM #temp
WHERE line IS NOT NULL
ORDER BY line;
DROP TABLE #temp;
PRINT @file;
SET @cmd='MOVE /Y C:\OLD\'+@file+' C:\NEW\receive.csv'
PRINT @cmd
EXEC sys.xp_cmdshell @cmd;
END
   

- Advertisement -