?
Solved

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

Posted on 2011-03-14
4
Medium Priority
?
1,471 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 750 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

771 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