SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 stop a xp_cmdshell after 1st pass
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

STCCM
Starting Member

1 Posts

Posted - 07/10/2013 :  11:28:48  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000