July 24, 2012 at 5:49 am
Hi ,
I need suggestions for following :
I am trying to copy a text file from One location to other location and After copying file Need to Delete file from source location and need to keep a log of this file
July 24, 2012 at 7:01 am
I got the solution from one of my colleagues
Please find the solution below
DECLARE @from VARCHAR(200)
DECLARE @to VARCHAR(200)
DECLARE@to_move VARCHAR(200)
DECLARE @sql VARCHAR(200)
DECLARE @sql_mov VARCHAR(200)
DECLARE @sql_del VARCHAR(200)
SELECT @to = '\\X\20120724.txt',
@from = '\\Y\20120724.txt',
@to_move = '\\Z\20120724.txt'
SET @sql = 'copy ' + @from + ' ' + @to
SET@sql_mov = 'copy ' + @from + ' ' + @to_move
SET@sql_del = 'del ' + @from
EXECUTE master..xp_cmdshell @sql
EXECUTE master..xp_cmdshell @sql_mov
EXECUTE master..xp_cmdshell @sql_del
July 24, 2012 at 7:14 am
Rakesh.Chaudhary (7/24/2012)
I got the solution from one of my colleaguesPlease find the solution below
DECLARE @from VARCHAR(200)
DECLARE @to VARCHAR(200)
DECLARE@to_move VARCHAR(200)
DECLARE @sql VARCHAR(200)
DECLARE @sql_mov VARCHAR(200)
DECLARE @sql_del VARCHAR(200)
SELECT @to = '\\X\20120724.txt',
@from = '\\Y\20120724.txt',
@to_move = '\\Z\20120724.txt'
SET @sql = 'copy ' + @from + ' ' + @to
SET@sql_mov = 'copy ' + @from + ' ' + @to_move
SET@sql_del = 'del ' + @from
EXECUTE master..xp_cmdshell @sql
EXECUTE master..xp_cmdshell @sql_mov
EXECUTE master..xp_cmdshell @sql_del
If you're going to use xp_CmdShell for this, there is a MOVE command in DOS and in ROBOCOPY.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2012 at 8:12 am
Thanks for the information about MOVE command. I was not aware about this earlier.
I have now implemented my requirement using the MOVE command.
Is there any other way to implement this other than using the xp_cmshell option?
July 24, 2012 at 8:41 am
Other option is to explore SSIS..
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply