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
Solved

xp_cmdshell copy file and append date to name

Posted on 2003-10-28
6
1,952 Views
Last Modified: 2007-12-19
I am trying to copy a file and append the date to the name - I do not want the time, date only - using the xp_cmdshell (unless there is a better way) - I cannot get the date concatentaion for the life of me?

declare @rc int, @varDate sysname
SET @varDate = getdate()
exec @rc = master..xp_cmdshell 'copy c:\test\test_error_log.txt c:\test\test_error_log_"+@varDate+".txt', no_output
select @rc
0
Comment
Question by:tbaseflug
  • 3
  • 3
6 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 9636178
Too many Open questions.
0
 

Author Comment

by:tbaseflug
ID: 9636184
I know - I am making the effort today to go and close some of them out - have been out of town for the past few months and have not had chance for cleanup
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 9636232
In that case, maybe try something like this:


declare @rc int
DECLARE @cmd VARCHAR(500)
SET @cmd = 'copy c:\test\test_error_log.txt c:\test\test_error_log_' +
      CONVERT(CHAR(8), GETDATE(), 112) + '.txt'
exec @rc = master..xp_cmdshell @cmd, NO_OUTPUT
select @rc

This will put the date in YYYYMMDD format; if you need another format, just let me know :-)
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:tbaseflug
ID: 9636245
wow - works great!  How would I format the date to something like:
mm_dd_yy
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 125 total points
ID: 9636317
REPLACE(CONVERT(CHAR(8), GETDATE(), 1), '/', '_')
0
 

Author Comment

by:tbaseflug
ID: 9636342
Awesome!  Thanks!!!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
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…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

840 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