We help IT Professionals succeed at work.
Get Started

exporting a bcp xml file out of sql 2005 with a date on the file

Last Modified: 2012-05-09

I am running the following script every 2 hours, what I want is to only keep 5 current, but each to have time stamp on the file. ie myview.xml will be myview010.xml  for file generated at 10.00am myview.xml for file generated at 12.00

the current script I am using setup in an sql agent job to run every two hours is

exec master..xp_cmdshell 'bcp "SELECT * FROM mydatabase..myview for XML RAW(''myview''), XMLSCHEMA(''URN:myview.COM'')" queryout \\webserver\internet\myview.xml -S MYserver -U testuser -P xxxx -c -t'

how do i insert a timestamp in the file name?
or we could have myview1.xml, myview2.xml, myview3.xml?

After 5 files have been created I want to remove the earliest
can sql do this or would it better that windows schedular remove the files on the webserver?
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE