SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Current Date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

divan
Posting Yak Master

153 Posts

Posted - 10/25/2012 :  07:47:08  Show Profile  Reply with Quote
I have the following copy statement in my sql scheduler

COPY C:\Reports\TRIBUTE_DETAIL_IND.xls D:\TEMP\TDC\TRIBUTE_DETAIL_IND.xls

how do I append the date the file is being copied to the end of the file name so the file name looks like

TRIBUTE_DETAIL_IND_102512.xls

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 10/25/2012 :  08:02:57  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
something like

copy C:\Reports\TRIBUTE_DETAIL_IND.xls D:\TEMP\TDC\TRIBUTE_DETAIL_IND_%date:~3,2%%date:~0,2%%date:~8,2%.xls

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 10/25/2012 :  08:14:08  Show Profile  Reply with Quote
did not like the command.. "The syntax of the command is incorrect. Process Exit Code 1. The step failed."

PS: I am using sql 2005
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2215 Posts

Posted - 10/25/2012 :  08:25:32  Show Profile  Reply with Quote
DECLARE @var1 varchar(100) = 'D:\SQLServer\Projects\Walmart\Scripts\DUMP\MedChive_Data.xls'
DECLARE @var2 varchar(100) = left(@var1, len(@var1)-4) + '_' + REPLACE(CONVERT(VARCHAR(8), SYSDATETIME(), 1), '/', '') + '.xls'
DECLARE @SQL1 VARCHAR(300)
--COPY A NEW ONE IN
SET @SQL1 = 'xp_cmdshell ' + CHAR(39) + 'COPY ' + @var1 + ' ' + @var2 + CHAR(39)
PRINT @sQL1
EXEC (@SQL1)

--
Chandu

Edited by - bandi on 10/25/2012 08:28:05
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/25/2012 :  10:10:30  Show Profile  Reply with Quote
xp_cmdshell is disabled by default so make sure you check if its enabled before you use it.



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


Edited by - visakh16 on 10/25/2012 10:10:40
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 10/25/2012 :  10:47:57  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
How are you running it?
That should work from a bat file or command window - maybe it's being parsed before executing.

Try it from a command window first.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2215 Posts

Posted - 10/26/2012 :  02:43:23  Show Profile  Reply with Quote
To enable xp_cmdshell feature, follow these steps


EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000