Solved

master.dbo.xp_cmdshell RENAME is not renaming...

Posted on 2011-03-14
4
1,437 Views
Last Modified: 2012-05-11
I created a DTS package and one of the tasks is to rename my X_MMBS_DATA.CSV file to a filenameyyyymmdd.CSV format.  

Although the same code runs on my other DTS, it does not run on this one and I can't figure it out.  :(    

I don't get an error message.
DECLARE @sql varchar(4000),
        @dt varchar(500)
 
-- Get date and time 
 
SELECT  @dt = 
convert(varchar(4),datepart(year,getdate()))+ ''+
right('0'+convert(varchar(3),datepart(month,getdate())),2)+''+
right('0'+convert(varchar(4),datepart(day,getdate())),2)
 
    
-- rename file
 
SELECT    
@sql = 'master.dbo.xp_cmdshell ''rename \\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATA.CSV  MmbsData'+ @dt+'.CSV'''
--print @sql
exec (@sql)

Open in new window

0
Comment
Question by:epicazo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 35130783
Any chance the file is still in use, and the rename is failing because of that? You might want to redirect error output to a log file:
sql = 'master.dbo.xp_cmdshell ''rename \\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATA.CSV  MmbsData'+ @dt+'.CSV 2>\\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATA.err.log'''
0
 

Author Comment

by:epicazo
ID: 35133594
I don't beleive the file is in use because (X_MMBS_DATA.CSV) is a newly created file by the previous task.  It almost seems as it is ignoring the Exec (Sql) statement.

@sql = 'master.dbo.xp_cmdshell ''rename \\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATA.CSV MmbsData'+ @dt+'.CSV >\\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATAerr.log'''
exec (@sql)
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 250 total points
ID: 35133656
Try
@sql = 'master.dbo.xp_cmdshell ''echo rename \\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATA.CSV MmbsData'+ @dt+'.CSV >\\10.41.32.139\rootsftp$\RadAdvocate\X_MMBS_DATAerr.log''' 
exec (@sql)

Open in new window

and see if the log file is created, and whether it shows the rename command.
0
 

Author Closing Comment

by:epicazo
ID: 35140995
The problem was with my permissions in the SFTP folder.   lol!    I appreciate your help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question