Copy File and error code



I'm copying a file across the network. My code works, but it returns the below results when successful. Is there any way to modify my code to force sql to return perhaps a simple 0 for success and maybe 1 for an error?


CODE:

DECLARE @sMsg varchar(3000)
DECLARE @sSource varchar(1000)
DECLARE @sTarget varchar(1000)

SET @sSource = '\\Server1\C\data\myDB.MDB'
SET @sTarget = 'D:\Data\myDB.MDB'

--SET @sMsg = N'copy ' + @sSource + N' ' + @sTarget
SET @sMsg = 'copy "' + @sSource + '" "' + @sTarget + '"';
EXEC master.dbo.xp_cmdshell @sMsg


RESULTS:

1 file(s) copied
NULL

.



Relevant Pages

  • Re: Copy File and error code
    ... DECLARE @ret int ... DECLARE @sMsg varchar ... DECLARE @sSource varchar ...
    (microsoft.public.sqlserver.programming)
  • Re: Copy File and error code
    ... return code to get success or failure: ... DECLARE @sMsg varchar ... DECLARE @sSource varchar ... EXEC master.dbo.xp_cmdshell @sMsg ...
    (microsoft.public.sqlserver.programming)
  • Re: Copy File and error code
    ... Is there any way to modify my code to force sql to return perhaps a simple 0 for success and maybe 1 for an error? ... DECLARE @sMsg varchar ... DECLARE @sSource varchar ... EXEC master.dbo.xp_cmdshell @sMsg ...
    (microsoft.public.sqlserver.programming)

Loading