October 23, 2018 at 6:56 am
Hello,
I have an issue with the cmdexec script below : I can't get variable content to use it like parameter in a copy statement.
1- I get a string (the file name) from 1st file Headers.csv into variable %%i. This file has only 1 line. %%i content is Final_2018-01-01_181500.csv for example (no spaces in the name)
2- I set variable filename with %%i content
3- I concatenate 2 files Headers.csv and Content.csv in a third file named %filename%
The third file is never created when I execute the SQL job. Why ?
But when I execute the same script from DOS console, it works perfectly !!!
SET file_name=
FOR /F "tokens=6 delims=;" %%i in ('type \\SRVSQL\Headers.csv') do (
SET file_name=%%i
)
copy \\SRVSQL\Headers.csv + \\SRVSQL\Content.csv \\SRVSQL\%file_name%
Can anybody help me to solve this issue ?
Thanks for your help.
October 23, 2018 at 7:26 am
lgalland - Tuesday, October 23, 2018 6:56 AMHello,
I have an issue with the cmdexec script below : I can't get variable content to use it like parameter in a copy statement.
1- I get a string (the file name) from 1st file Headers.csv into variable %%i. This file has only 1 line. %%i content is Final_2018-01-01_181500.csv for example (no spaces in the name)
2- I set variable filename with %%i content
3- I concatenate 2 files Headers.csv and Content.csv in a third file named %filename%
The third file is never created when I execute the SQL job. Why ?
But when I execute the same script from DOS console, it works perfectly !!!SET file_name=
FOR /F "tokens=6 delims=;" %%i in ('type \\SRVSQL\Headers.csv') do (
SET file_name=%%i
)
copy \\SRVSQL\Headers.csv + \\SRVSQL\Content.csv \\SRVSQL\%file_name%
Can anybody help me to solve this issue ?
Thanks for your help.
Does the SQL Server Agent service account have the necessary permissions, access to the unc path?
Sue
October 23, 2018 at 8:00 am
Hello Sue,
yes, the permissions are OK because when I put a string like Final.csv instead of %file_name%, I have no error. The file is well created.
October 24, 2018 at 3:31 pm
lgalland - Tuesday, October 23, 2018 8:00 AMHello Sue,
yes, the permissions are OK because when I put a string like Final.csv instead of %file_name%, I have no error. The file is well created.
Have you tried putting it all in a batch file and calling that?
I've seen the issue where multiple commands won't execute but that doesn't seem to be the issue in your case.
Sue
October 24, 2018 at 5:11 pm
I may be wrong, but all attempts I made at executing a cmdexec step only the first line on the command works.
e.g. no multiple lines are possible so your sample above will only work, as far as I know, is done on a .bat file.
Also I would possibly advise you to do this with powershell - more functionality and can be typed directly on the job step (although I still prefer doing those on a script and use cmdexec to execute them)
sample powershell - assuming I got the meaning of the for /i
$file_name = (Get-Content "\\SRVSQL\headers.csv").Split(";")[5] # zero based so this gets the 6th header
Get-Content "\\SRVSQL\Headers.csv","\\SRVSQL\Content.csv"|Set-Content "\\SRVSQL\$($file_name).csv"
October 24, 2018 at 5:28 pm
frederico_fonseca - Wednesday, October 24, 2018 5:11 PMI may be wrong, but all attempts I made at executing a cmdexec step only the first line on the command works.e.g. no multiple lines are possible so your sample above will only work, as far as I know, is done on a .bat file.
Also I would possibly advise you to do this with powershell - more functionality and can be typed directly on the job step (although I still prefer doing those on a script and use cmdexec to execute them)
sample powershell - assuming I got the meaning of the for /i
$file_name = (Get-Content "\\SRVSQL\headers.csv").Split(";")[5] # zero based so this gets the 6th header
Get-Content "\\SRVSQL\Headers.csv","\\SRVSQL\Content.csv"|Set-Content "\\SRVSQL\$($file_name).csv"
I thought it was the one line issue too - I've always had to use && between commands and on one line.
And why I use Powershell more often instead.....
Sue
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy