Solved

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

Posted on 2011-03-14
4
1,373 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
  • 2
  • 2
4 Comments
 
LVL 68

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 68

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now