Author |
Topic |
Jmunoz69
Starting Member
6 Posts |
Posted - 2009-10-20 : 13:09:09
|
I need to create multiple daily flat files and they must not overwrited each other. What do I need to do to edit this logic?here is the logic usedSet @Filename = (SELECT ('C:\Reports_Out\ReturnShip.2009.'+ substring(convert(varchar,getdate(), 101),1,2)+ '' + substring(convert(varchar,getdate(), 101),4,2)+ ''+ substring(convert(varchar,getdate(), 101),7,4) + '.txt' ) as Filename ) |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Jmunoz69
Starting Member
6 Posts |
Posted - 2009-10-20 : 14:08:20
|
Thanks TaraThis worked great, Can logic be modifed so that the filename does not include timestamp, but add "_1" when it encounters the same filename?Thanks again |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Jmunoz69
Starting Member
6 Posts |
Posted - 2009-10-20 : 15:22:54
|
Thanks TaraWould like filenames to follow this naming convention:ReturnShip.2009.10202009.txtReturnShip.2009.10202009_1.txtReturnShip.2009.10202009_2.txt I need to create multiple daily flat files and they must not overwrited each other. What do I need to do to edit this logic?here is the logic usedSet @Filename = (SELECT ('C:\Reports_Out\ReturnShip.2009.'+substring(convert(varchar,getdate(), 101),1,2)+ '' + substring(convert(varchar,getdate(), 101),4,2)+ ''+ substring(convert(varchar,getdate(), 101),7,4) + '.txt' ) as Filename ) |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2009-10-20 : 16:08:48
|
Here you go:DECLARE @s varchar(50), @i smallintSET @i = 1SET @s = 'ReturnShip.' + CONVERT(char(4), YEAR(GETDATE())) + '.' + REPLACE(CONVERT(char(10), GETDATE(), 101), '/', '') SET @s = CASE WHEN @i > 0 THEN @s + '_' + CONVERT(varchar(3), @i) ELSE @s ENDSET @s = @s + '.txt'PRINT @s Just change @i to whatever increment you are on.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog"Let's begin with the premise that everything you've done up until this point is wrong." |
 |
|
Jmunoz69
Starting Member
6 Posts |
Posted - 2009-10-20 : 16:27:50
|
PerfectVery much appreciative of your helpThanks again |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|