November 17, 2011 at 9:07 am
Hi,
I am trying to rename a file through SQL Server.
I always receive an error saying that the sintax is incorrect.
Can someone please help?
Thank you.
Command:
declare @command varchar(8000)
set @command = 'rename c:\sgrs\SGRS_SGCTCentral_7_20111111102846.rar c:\sgrs\verificadoSGRS_SGCTCentral_7_20111111102846.rar'
exec master.dbo.xp_cmdshell @command
November 17, 2011 at 9:18 am
Is that syntax error coming from SQL Server or from the Cmd Exec? Please post the exact error message.
Thanks
John
November 17, 2011 at 9:21 am
declare @command varchar(8000)
set @command = 'rename c:\sgrs\SGRS_SGCTCentral_7_20111111102846.rar verificadoSGRS_SGCTCentral_7_20111111102846.rar'
exec master.dbo.xp_cmdshell @command
__________________________
Allzu viel ist ungesund...
November 17, 2011 at 9:23 am
river1 (11/17/2011)
I am trying to rename a file through SQL Server.
I don't want to irritate you with useless so-called advice, but... why are you doing it in T-SQL?
Don't you think that a batch script, VBScript or any other programming language would be a better choice for this task?
-- Gianluca Sartori
November 17, 2011 at 9:24 am
I need to do it in t-sql.
November 17, 2011 at 9:27 am
When i run the t-sql, it gives me backup a table with a column named output.
This grid as two rows.
The firts says : The syntax of the command is incorrect.
The secund : NULL
November 17, 2011 at 9:32 am
Remove the path from the target name for the file, so that you specify only the file name itself.
John
November 17, 2011 at 9:36 am
I made as you told me to:
declare @cmd as varchar(8000)
set @cmd = ' ren c:\sgrs\SGRS_SGCTCentral_7_20111111102846.rar
verificado1.rar'
EXEC master..xp_cmdshell @cmd
Same error....
🙁
November 17, 2011 at 9:36 am
river1 (11/17/2011)
I need to do it in t-sql.
Lowell
November 17, 2011 at 9:39 am
Looks correct. The only thing I can think of is that you have a carriage return character in your command.
John
November 17, 2011 at 9:40 am
"carriage return character" sorry, what's that? (My english is not very good)
November 17, 2011 at 9:42 am
It's what you get when you press the "Return" or "Enter" key on your keyboard.
John
November 17, 2011 at 9:44 am
make sure the string is a single line when sent to the cmd :
create table #Results (
ID int identity(1,1) NOT NULL,
TheOutput varchar(1000))
declare @cmd as varchar(8000)
set @cmd = ' ren c:\sgrs\SGRS_SGCTCentral_7_20111111102846.rar verificado1.rar'
insert into #Results (TheOutput)
EXEC master..xp_cmdshell @cmd
select * from #Results
Lowell
November 17, 2011 at 9:48 am
Problem solved with Lowel suggestion.
Thank you very much for the help.
November 17, 2011 at 9:49 am
It had to be in a single line!
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply