| Author |
Topic |
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-03-23 : 14:19:03
|
| Hello All -I need some ideas to how add a date to a filename, here's the scenario.40 reports gets generated from template using a Activex (it copies from the template and puts into a new location) I need to take the reports and put into another location with dates on the file name, something like Report_YYYYMMDD_Bank.xls.Any ideas ?Thanks!Igor. |
|
|
jason
Posting Yak Master
164 Posts |
Posted - 2005-03-23 : 14:57:45
|
| declare @thisday varchar (30)declare @filename varchar(255)declare @path varchar(255)set @thisday = getdate()set @filename = 'Report_' + Convert(varchar(4),Year(@thisday)) + Convert(varchar(2),Month(@thisday)) + Convert(varchar(2),Day(@thisday)) + Convert(varchar(2),datename(hh,@thisday)) + Convert(varchar(2),datename (mi,@thisday)) + '_Bank.xls'set @path = '<your file path text>\' + @filename |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-03-23 : 15:14:30
|
I prefer to archive the data to it's own datestamped folder Select @FilePath = 'd:\Data\Tax\OracleExtracts' , @MoveDate = replace(replace(Rtrim(convert(char(50),GetDate())),' ','_'),':','_') SET @cmd = 'MD ' + @FilePath + '\Archive\' + @MoveDate SET @Command_string = 'EXEC master..xp_cmdshell ''' + @cmd + ''', NO_OUTPUT' Exec(@Command_String) SET @cmd = 'MOVE ' + @FilePath + '\*.* ' + @FilePath + '\Archive\' + @MoveDate SET @Command_string = 'EXEC master..xp_cmdshell ''' + @cmd + ''', NO_OUTPUT' Exec(@Command_String) Brett8-) |
 |
|
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-03-23 : 17:33:26
|
| It's not working for me, I'm getting errors...Igor. |
 |
|
|
jason
Posting Yak Master
164 Posts |
Posted - 2005-03-23 : 18:26:08
|
| what are the errors and from which example? |
 |
|
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-03-24 : 13:29:30
|
| Server: Msg 105, Level 15, State 1, Line 1Unclosed quotation mark before the character string 'MD N:\ ...Igor. |
 |
|
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-03-24 : 13:32:18
|
| on the second example...Igor. |
 |
|
|
jason
Posting Yak Master
164 Posts |
Posted - 2005-03-24 : 14:05:27
|
| can we see the SQL? |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-03-28 : 03:27:32
|
will this do?declare @file varchar(200)set @file='report_' + replace(convert(varchar(10),getdate(),120),'-','') + '_bank.xls'print @file --------------------keeping it simple... |
 |
|
|
igorblackbelt
Constraint Violating Yak Guru
407 Posts |
Posted - 2005-04-05 : 11:49:36
|
| I'll try, I'll let you guys know, if you come up with something else, let me know...Thanks!Igor. |
 |
|
|
rfrancisco
Yak Posting Veteran
95 Posts |
Posted - 2005-04-05 : 12:10:30
|
| You can also use this one:declare @file varchar(200)set @file='report_' + convert(varchar(10),getdate(),112) + '_bank.xls'print @file |
 |
|
|
|