0

This is my SQL command that works

SET @Command = 'REN "C:\Nielsen\' + @FileName + '" "'
+ RIGHT(@FileName,LEN(@FileName)-11) + '"'

I want to replace the C:\Nielsen\ with the value from a variable called @Nielsen

This does not work.....what am I missing?

SET @Command = 'REN ' + @Nielsen + @FileName  
+ RIGHT(@FileName,LEN(@FileName)-11) + ''

EDIT

Error message is:

The syntax of the command is incorrect.

4
  • 2
    Please define "does not work" - what did you expect, what do you see? Commented Mar 13, 2013 at 9:29
  • I am missing something because the error is The syntax of the command is incorrect. Commented Mar 13, 2013 at 9:30
  • 1
    Your first version has a space between @Nielsen and @Filename. Perhaps you need that in your second version as well? Commented Mar 13, 2013 at 9:33
  • @etienne - do you get the error on the Set @Command line, or when you execute the command you built (you are missing some " and spaces)? Commented Mar 13, 2013 at 9:35

1 Answer 1

5

You could break it down like below (Sorry formatting doesn't work properly due to escape characters):

--Same string without variable 
SET @Command = 'REN "' + 'C:\Nielsen\' + @FileName + '" "'
+ RIGHT(@FileName,LEN(@FileName)-11) + '"'

--Same string with variable 
SET @Command = 'REN "' + @Nielsen + @FileName + '" "'
+ RIGHT(@FileName,LEN(@FileName)-11) + '"'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.