﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Date in BCP out file name / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 10:46:46 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>[quote][b]PhilPacha (2/21/2013)[/b][hr]Since you are running a SQL Server Agent job, you can use SQL Server Agent tokens.The one for date the Job started running is:  $(ESCAPE_NONE(STRTDT))Here's a link to the 2008R2 help...http://msdn.microsoft.com/en-us/library/ms175575.aspx[/quote]Great, thank you!I'm going to try it!gmac</description><pubDate>Fri, 22 Feb 2013 06:13:33 GMT</pubDate><dc:creator>gmac 41947</dc:creator></item><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>Since you are running a SQL Server Agent job, you can use SQL Server Agent tokens.The one for date the Job started running is:  $(ESCAPE_NONE(STRTDT))Here's a link to the 2008R2 help...http://msdn.microsoft.com/en-us/library/ms175575.aspx</description><pubDate>Thu, 21 Feb 2013 15:30:31 GMT</pubDate><dc:creator>PhilPacha</dc:creator></item><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>[quote][b]gmac 41947 (2/21/2013)[/b][hr]If I insert variable in SQL JOB Step, the JOB exec stopped with error.When I insert throughout code (variables, bcp command...) in .bat file, and I reference this file in SQL JOB, the JOB was successfully executed.This is very interesting! Why get error, if code in JOB step, and why not if code insert in .bat file?[/quote]Those variables and string manipulation functions are native to the DOS command shell only. So you have to be running from a .bat file to use them.  Now that you have told me this was a SQLAgent job step, you could have generated file name with the current date in it using SQL, then passed the file name as a parameter to the .bat file.Anyway, glad you got it working.</description><pubDate>Thu, 21 Feb 2013 06:20:54 GMT</pubDate><dc:creator>sturner</dc:creator></item><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>If I insert variable in SQL JOB Step, the JOB exec stopped with error.When I insert throughout code (variables, bcp command...) in .bat file, and I reference this file in SQL JOB, the JOB was successfully executed.This is very interesting! Why get error, if code in JOB step, and why not if code insert in .bat file?Sorry for my english!Thanksgmac</description><pubDate>Thu, 21 Feb 2013 01:57:45 GMT</pubDate><dc:creator>gmac 41947</dc:creator></item><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>[quote][b]Jeff Moden (2/20/2013)[/b][hr]Can you think of a way to have the date come out in the ISO format of YYYYMMDD to support sortable file names using the batch commands?[/quote]didling with the String manipulation function in shell is a pain, but yes you can do it.from what I understand you have to play some tricks to combine variables.(I looked at this: http://stackoverflow.com/questions/7846560/how-concatenate-two-variables-in-batch-script)anyway, I would start by getting each part of the current DATE into three variables:set MM=%DATE:~4,2%set DD=%DATE:~7,2%set YY=%DATE:~10,4%then create your new yymmdd variable by combining them:setlocal EnableDelayedExpansionset yyyymmdd=!%YY%%MM%%DD%!I hate messing with batch scripting because it is so ugly (not like unix shells) but if you are a DBA you end up needing to use it at times.</description><pubDate>Wed, 20 Feb 2013 08:38:51 GMT</pubDate><dc:creator>sturner</dc:creator></item><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>[quote][b]sturner (2/20/2013)[/b][hr]you are running bcp from a shell, so get the current date (M/D/Y) part into a variable:set DATEVAR=%DATE:~4,10%as part of a filename you probably want to change the /  to -   like this:set mydate=%DATEVAR:/=-%then you can use %mydate%  in your batch command wherever you want the current date, like today would be: 02-20-2013[/quote][strike]What language are you using?  This doesn't appear to be T-SQL.[/strike]Never mind.  I get it.  These are batch commands at the command line level.  Well done.Can you think of a way to have the date come out in the ISO format of YYYYMMDD to support sortable file names using the batch commands?</description><pubDate>Wed, 20 Feb 2013 08:20:45 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>you are running bcp from a shell, so get the current date (M/D/Y) part into a variable:set DATEVAR=%DATE:~4,10%as part of a filename you probably want to change the /  to -   like this:set mydate=%DATEVAR:/=-%then you can use %mydate%  in your batch command wherever you want the current date, like today would be: 02-20-2013</description><pubDate>Wed, 20 Feb 2013 07:33:54 GMT</pubDate><dc:creator>sturner</dc:creator></item><item><title>Date in BCP out file name</title><link>http://www.sqlservercentral.com/Forums/Topic1421963-391-1.aspx</link><description>Hi,How can I insert current date in BCP out file name?I use this command, in SQL JOB step (type: Operating System ComdExec)bcp "SELECT * FROM NW.dbo._au_NAPI" queryout "E:\kon_[b]DATE[/b].csv" -CACP -c -T -t"\";\"" -r"\"\"" -S DBHave you any ideas?Thanks,gmac</description><pubDate>Wed, 20 Feb 2013 01:21:18 GMT</pubDate><dc:creator>gmac 41947</dc:creator></item></channel></rss>