November 30, 2011 at 8:11 am
I am using the following to rename a fil in a location. It works but renames it as @MyFileNametxt'
Any ideas what I have done wrong???
DECLARE @MyFileNametxt varchar(50)
set @MyFileNametxt = 'PASS_ASR_ALL_' + CAST(DATEPART(YYYY, GETDATE()) AS varCHAR(4)) +'_'+ CAST(DATEPART(MM, GETDATE()) AS varCHAR(2)) +'_'+ CAST(DATEPART(DD, GETDATE()) AS varCHAR(2))+'_'+CAST(DATEPART(HOUR, GETDATE()) AS varCHAR(2)) +'_'+ CAST(DATEPART(MINUTE, GETDATE()) AS varCHAR(2))
+'_'+ CAST(DATEPART(SECOND, GETDATE()) AS varCHAR(2))+'.txt'
EXEC master..xp_cmdshell 'RENAME "D:\WebFiles\Web Update File Out\*** Update Files\RASS_ASR_ALL.txt" @MyFileNametxt'
November 30, 2011 at 8:19 am
try it this way:
declare @execmd varchar(4000)
set @execmd = 'execute master..xp_cmdshell ''RENAME "D:\WebFiles\Web Update File Out\*** Update Files\RASS_ASR_ALL.txt" "' + @MyFileNametxt +'"'
exec(@execmd)
The probability of survival is inversely proportional to the angle of arrival.
November 30, 2011 at 8:21 am
your snippet has the string hardcoded, isntead of substituting the variable.
something like this is what you are after, i think.
DECLARE @MyFileNametxt varchar(50)
DECLARE @cmd as varchar(1000)
set @MyFileNametxt = 'PASS_ASR_ALL_' + CAST(DATEPART(YYYY, GETDATE()) AS varCHAR(4)) +'_'+ CAST(DATEPART(MM, GETDATE()) AS varCHAR(2)) +'_'+ CAST(DATEPART(DD, GETDATE()) AS varCHAR(2))+'_'+CAST(DATEPART(HOUR, GETDATE()) AS varCHAR(2)) +'_'+ CAST(DATEPART(MINUTE, GETDATE()) AS varCHAR(2))
+'_'+ CAST(DATEPART(SECOND, GETDATE()) AS varCHAR(2))+'.txt'
SET @cmd = 'RENAME "D:\WebFiles\Web Update File Out\*** Update Files\RASS_ASR_ALL.txt" ' + @MyFileNametxt
EXEC master..xp_cmdshell @cmd
Lowell
November 30, 2011 at 8:31 am
Thanks that works perfectly. Thanks for the quick response
November 30, 2011 at 8:35 am
kyle.doouss (11/30/2011)
Thanks that works perfectly. Thanks for the quick response
Wouldn't you like to know the reason of failure of your code? 😛
November 30, 2011 at 8:41 am
Hello again. What about this one. Can I still apply the same principle as before? Could you tweak it for me?
DECLARE @MyFileName varchar(50)
set @MyFileName = 'PASS_ASR_ALL_' + CAST(DATEPART(YYYY, GETDATE()) AS varCHAR(4)) +'_'+ CAST(DATEPART(MM, GETDATE()) AS varCHAR(2)) +'_'+ CAST(DATEPART(DD, GETDATE()) AS varCHAR(2))+'_'+CAST(DATEPART(HOUR, GETDATE()) AS varCHAR(2)) +'_'+ CAST(DATEPART(MINUTE, GETDATE()) AS varCHAR(2))
+'_'+ CAST(DATEPART(SECOND, GETDATE()) AS varCHAR(2))+'.zip'
EXEC UDEF_KD_CompressFile 'D:\WebFiles\Web Update File Out\*** Update Files\@MyFileName', 'D:\WebFiles\Web Update File Out\*** Update Files\@MyFileNametxt'
November 30, 2011 at 9:17 am
It alright, I have sorted. Thanks for your help I am starting to understand the principles now
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply