I have a job that queries a view then exports the contents to a text file using cbp and xp_cmdshell. Everything works fine but I'm trying to add a datestamp on the file name and can't figure it out. Any assistance is greatly appreciated.
DECLARE @_FileName VARCHAR(256)
SELECT @_FileName = 'c:\payment_initiative' + REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(30), GETDATE(), 20), '-', ''), ' ', ''), ':', '') + '.txt'
EXEC master..xp_cmdshell 'bcp "SELECT * FROM ITMAS500_app.dbo.Payment_Initiative" queryout = @_FileName -T -c '
DECLARE @_FileName VARCHAR(256)
SELECT @_FileName = 'c:\payment_initiative' + REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(30), GETDATE(), 20), '-', ''), ' ', ''), ':', '') + '.txt'
EXEC master..xp_cmdshell 'bcp "SELECT * FROM ITMAS500_app.dbo.Payment_Initiative" queryout = @_FileName -T -c '