0

I am working on a FILE that I need to move from one loacation to another, but when I run the code below I keep getting an error that it has the incorrect syntax. When I print the @Move statement I get this: (Which is what I think I should get)

MOVE \appdev1\sqltest\RedFlag\RedFlag Address Change New Debit Issued.pdf \appdev1\sqltest\RedFlag\2013-10-24_REDFLAG_.pdf

I am trying to run it like this:

EXEC MASTER.DBO.XP_CMDSHELL @MOVE

Any suggestions on what I am doing wrong? Do I need to add the ' in front of the Move statement?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
user2084896
  • 33
  • 1
  • 1
  • 5

1 Answers1

3

You have spaces in your paths/filenames, so you need to surround with double quotes.

SET @MOVE = 'MOVE "\\appdev1\... Issued.pdf" "\\appdev1\..._.pdf"';

If you are constructing a path from variables, this doesn't change anything. Staying in T-SQL, you would have parameters like this I presume:

SET @MOVE = 'MOVE "' + @OldFile + '" "' + @Printed + '"';

You'll have to work it out yourself if you are doing this in some other language. Here is a short demonstration of how it works in T-SQL:

DECLARE @MOVE VARCHAR(255), 
  @OldFile VARCHAR(255) = '\\foo\some filename.pdf', 
  @Printed VARCHAR(244) = '\\blat\something else.pdf';

SET @MOVE = 'MOVE "' + @OldFile + '" "' + @Printed + '"';

PRINT @MOVE;

Results:

MOVE "\\foo\some filename.pdf" "\\blat\something else.pdf"

I don't see any extra quotes, so maybe those are coming from whatever value you have in your parameters.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
  • The Move(parameter) is actually setup using the variables. so it is like set Move(parameter) = 'Move ' + _OldFile + ' ' + _Printed – user2084896 Oct 24 '13 at 17:39
  • I'm not doing it any other language, I just didnt see the bottom part of your answer, which still gave me too many quotes. I really think the smart comments could have been left behind though, I just came on here for help. – user2084896 Oct 24 '13 at 17:50
  • @user2084896 I don't understand what you mean by "too many quotes" - and I presumed it was a different language because you can't have a parameter named `_OldFile` in T-SQL. So, what does `_OldFile` contain? – Aaron Bertrand Oct 24 '13 at 17:55
  • @user2084896 And yes, you came on here for help. For free, I might add. But you have to show a little effort on your side, and don't really have a lot of room to complain. You're the one who needs to solve a problem, not the people who are taking time out of their day to help you. – Aaron Bertrand Oct 24 '13 at 18:01