Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a batch script which extract SQL data to CSV file:

bcp Database.dbo.MyTable out C:\Reports\Output.csv -s ServerName -T -c

I need the name of the output file to contain the current date.

For example the output file has to be of the following format: Result_2012_12_31csv.

I guess the DATE function has to be used here as an argument.

How I can do that?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This should do what you want (as I understand it).

bcp Database.dbo.MyTable out C:\Reports\Output_%date:~10,4%_%date:~4,2%_%date:~7,2%.csv -s ServerName -T -c

would result in:

bcp Database.dbo.MyTable out C:\Reports\Output_2012_08_14.csv -s ServerName -T -c
share|improve this answer
    
that works!!!! Thank you!!!! –  Anna Aug 15 '12 at 1:27
    
The further question is how to transfer headings as well? The output file does not contain them. –  Anna Aug 21 '12 at 23:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.